14
NeoSama
12d

While coding in C, I once forgot to add a semicolon at the end of a while loop polling a register value.
The logic required me to make it zero as soon as it read non-zero and continue the rest of the process. Hence the 'while' that missed the semicolon ended up being a single instruction assignment to the same volatile register that I kept polling. This caused synchronisation issue with the FPGA, and my code got stuck in an uncertain infinite loop.
Took me 2 days and a silly, yet valid question from my teammate to figure out the cause of this stupid bug.

Comments
  • 4
    That was unfortunate, but don't forget that the devrant tag is only for devrant related topics not Dev rants.
  • 4
    @p100sch Sorry, first-timer here. Thanks for the info :)
  • 4
    GCC 6 and later warns about misleading indentation when using -Wall, but unfortunately, that does not work in this specific case. I've just tested it.

    In the "forgotten semicolon" version, the statement after the while has the same indentation as the while because it wasn't meant to be in the while scope, but no warning.
  • 2
    @Fast-Nop Yeah. I was using gcc 7+ and -Wall was enabled
  • 3
    @NeoSama Holy shit, not even Clang 10 with -Wall -Wextra -Wpedantic finds that, and neither CppCheck. Good to know that this kind of bug needs manual attention.
  • 2
    @Fast-Nop All credit goes to my teammate for helping me figure out this bug.
  • 2
    There's a reason why many style guides require curly braces in all cases.
Add Comment