this post was submitted on 10 Nov 2024
190 points (95.2% liked)

Programmer Humor

32483 readers
384 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] cmnybo@discuss.tchncs.de 39 points 1 week ago (3 children)

You don't get segmentation faults if you don't have an MMU. That can certainly make debugging more interesting when your firmware starts overwriting memory that it shouldn't until it finally crashes.

[–] TimeSquirrel@kbin.melroy.org 24 points 1 week ago (1 children)

Sometimes you'll notice the side effects, like if you have a small OLED or LCD screen and start getting garbage characters in your strings.

[–] qprimed@lemmy.ml 18 points 1 week ago

or, if you are really lucky, you can poke the right locations and release the magic blue smoke from the chips. super fun and all the cool kids are doing it.

[–] mkwt@lemmy.world 12 points 1 week ago* (last edited 1 week ago)

Even if you do have an MMU, there's no guarantee that you'll get a segmentation fault from a memory bug. You can still just get the weird side effects, if you fail to access the incorrect memory.

Undefined behaviour means exactly that. You have no idea what you could get.

[–] litchralee@sh.itjust.works 9 points 1 week ago

I was once working on an embedded system which did not have segmented/paged memory and had to debug an issue where memory corruption preceded an uncommanded reboot. The root cause was a for-loop gone amok, intending to loop through a linked list for ever member of an array of somewhat-large structs. The terminating condition was faulty, so this loop would write a garbage byte or two, ever few hundred bytes in memory, right off the end of the 32 bit memory boundary, wrapping around to the start of memory.

But because the loop only overwrote a few bytes and then overflew large swaths of memory, the loop would continue passing through the entire address space over and over. But since the struct size wasn't power-of-two aligned, eventually the garbage bytes would write over the crucial reset vector, which would finally reboot the system and end the misery.

Because the system wouldn't be fatally wounded immediately, the memory corruption was observable on the system until it went down, limited only by the CPU's memory bandwidth. That made it truly bizarre to diagnose, as the corruption wasn't in any one feature and changed every time.

Fun times lol