]> git.ipfire.org Git - thirdparty/coreutils.git/commit
maint: avoid signed integer overflows
authorTobias Stoeckmann <tobias@stoeckmann.org>
Sun, 14 Jun 2020 12:47:11 +0000 (14:47 +0200)
committerPádraig Brady <P@draigBrady.com>
Mon, 15 Jun 2020 22:07:03 +0000 (23:07 +0100)
commit0fe9fdece735234819ead2cad7902ba9a6cd8487
treee3608f1c82abe5cc5dca6272be06198ae3a92f17
parent189776ff3bf34708fba5ffe32aa8720659bddf04
maint: avoid signed integer overflows

Since -LONG_MIN results in LONG_MIN again, the operation itself is
a signed integer overflow.

This can be observed with the following calls (best if compiled
with -ftrapv or -fsanitize=undefined):

  $ numfmt --padding=-9223372036854775808
  $ seq 1e-9223372036854775808

Technically, the change in seq "reduces" the precision, but a double
or long double that small would be represented as 0 anyway.

* src/numfmt.c: Explicitly disallow --padding=LONG_MIN.
* src/seq.c: Treat 1e$LONG_MIN as 1e-$LONG_MAX.
* tests/misc/numfmt.pl: Add a test case.
* tests/misc/seq-precision.sh: Likewise.

Fixes https://bugs.gnu.org/41850
src/numfmt.c
src/seq.c
tests/misc/numfmt.pl
tests/misc/seq-precision.sh