Hacker News new | ask | show | jobs
by K0balt 532 days ago
Those kinds are almost never that the bug isn’t created unless you don’t put in the printf, it’s that the bug only causes the overt manifestation when the printf isn’t there. The actual bug is almost always there in both situations.

It’s almost never the compiler. It’s almost never an error in the bare metal.

Almost.

1 comments

The bug in question was a out of bounds writing to a stack allocated buffer. The compiler would choose to store some variables to registers for optimization purposes. When calling a function - these registers' contents would get pushed to the stack. The faulty called function would modify those same register contents on the stack. When returning to the parent function and restoring the context - the registers would have faulty values.

When adding a print or a check - the compiler would choose different variables to store in the registers. They would still get overwritten by the faulty function but the bug would not be observed.

I agree that it's almost never the compiler's fault though - but sometimes its optimization choices make it harder to reproduce a bug.

Edit: The faulty function was a somewhat standard function, part of the SDK. This taught me that the standard functions are almost never faulty. Until they are :-)

Sounds like a fun one. I know Im a broken man because I actually-like- tracking down those kinds of bugs lol.