Skip to content

Fix UB in Juliet no-overflow: imaxabs() is not defined for minimum value

Franz Brauße requested to merge fb/fix-juliet-ub into main

As the title says, there is undefined behaviour in this task when data has the smallest intmax_t value (which for LP64 is -2^63). C99 7.8.2.1 specifically says

The imaxabs function computes the absolute value of an integer j. If the result cannot be represented, the behavior is undefined.218)

Footnote 218 is:

  1. The absolute value of the most negative number cannot be represented in two’s complement.

This MR fixes the task by short-circuiting the application of imaxabs() in this case. Thereby the property "no-overflow: false" is being retained.

Merge request reports