[fpc-devel] Dangerous optimization in CASE..OF

Florian Klaempfl florian at freepascal.org
Sun Jul 16 21:13:06 CEST 2017


Am 16.07.2017 um 21:08 schrieb Ondrej Pokorny:
> On 16.07.2017 20:42, Florian Klämpfl wrote:
>> "Ungültiger Maschinenbefehl (Speicherabzug geschrieben)" = Invalid
>> opcode (memory dump written).
>> Why? Because it does not range check before entering the jump table.
> 
> OK, I confess I am not a C guy (I hated it in the university even more
> than fortran). But for me:

...

> 
> ondrej at ondrej-linux:~/ctest$ gcc test.c
> ondrej at ondrej-linux:~/ctest$ ./a.out
> defaultondrej at ondrej-linux:~/ctest$
> 
> No error if I remove the default statement.

Indeed. This proves the exactly point. Undefined behaviour. The code
behaves randomly dependent on the compiler used and even the optimizer
switches.



More information about the fpc-devel mailing list