[fpc-devel] Data flow analysis (dfa) and "case ... of"

Florian Klämpfl florian at freepascal.org
Tue Jun 6 17:06:28 CEST 2017


Am 05.06.2017 um 20:49 schrieb Jonas Maebe:
> On 05/06/17 20:37, Denis Kozlov wrote:
>>
>>
>> On 05/06/2017 18:59, Jonas Maebe wrote:
>>> That is why I said "If range checking is off there or disabled via an explicit type cast, then
>>> the result is undefined by definition." You use an explicit typecast above.
>>
>> I just wanted to highlight that these cases as legal and I presume not
>> uncommon, particularly if values are deserialized and typecasted.
> 
> Then this de-serialisation code must perform range checking. Again: if you assign an invalid value
> to a variable by typecasting, disabling range checking, inline assembly, passing a pointer to C code
> and overwriting the value there, or in any other way, Pascal code that works with the resulting
> value has undefined behaviour. The program could crash, silently fail, raise a random exception at
> some point, or do anything else.
> 

For the record: this can already happen. If a jump table for a case statement is generated, the
compiler does not check the boundaries if the jump table covers the whole declared (!) range of the
case variable.




More information about the fpc-devel mailing list