expressions: Convert SYSMIS into int as INT_MIN during optimization too.
authorBen Pfaff <blp@cs.stanford.edu>
Sun, 10 Apr 2022 15:47:00 +0000 (08:47 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Sun, 10 Apr 2022 15:47:00 +0000 (08:47 -0700)
commit435b06ea1e6cefd2d540552e161a84a9b2cbef42
tree2cc9b89f08b5b1d024c13f4f8bbcb2fd540de669
parentf7cc11e1ec082a3f38c3323cd5dbbe319b9a6229
expressions: Convert SYSMIS into int as INT_MIN during optimization too.

In an expression like LPAD('abc', $sysmis), the LPAD function is evaluated
using a C function that takes an 'int' as its second argument.  During
expression evaluation, out-of-range values get converted into SYSMIS by
the NUM_TO_INTEGER operator that gets automatically inserted to ensure
that, and then SYSMIS gets converted into INT_MIN to pass to the C
function.  This worked OK for runtime evaluation, but the optimizer failed
to do the conversion of SYSMIS to INT_MIN, which yielded undefined
behavior.  Some platforms (e.g. GCC on x86) converted SYSMIS (which is
the second-smallest 'double' value) into INT_MIN, so no problem showed up
there, but other platforms yielded INT_MAX, causing unexpected failures.

This commit fixes the problem by explicitly converting SYSMIS into INT_MIN
during optimization.

Thanks to Friedrich Beckmann for reporting and uncovering the problem.
Bug #62267.
src/language/expressions/generate.py
src/language/expressions/optimize.c