https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90882

--- Comment #1 from Kevin Dewald <kevin.dewald at ieee dot org> ---
When compiling and running the attached code using GCC 7.4.0, the output prints
both 'true' and 'false'.

When testing if the variable 'boolean' is false, an XOR 1,EAX instruction is
executed on that memory position. Given that that position is currently storing
0x02 instead of 0x01, it's new value is 0x03, evaluating true by the TEST
opcode.

From what I've read, modifying a boolean variable with an int pointer is
undefined. Nevertheless, this feels unexpected from a programmers point of
view, and I might worry it might be exploited as a security flaw on
applications compiled with GCC.

I've tested the same code on clang and it behaves as expected, only printing
'true'.

Reply via email to