GNU bug report logs - #41850
[PATCH] maint: Avoid signed integer overflows

Previous Next

Package: coreutils;

Reported by: Tobias Stoeckmann <tobias <at> stoeckmann.org>

Date: Sun, 14 Jun 2020 12:48:01 UTC

Severity: normal

Tags: patch

Done: Paul Eggert <eggert <at> cs.ucla.edu>

Bug is archived. No further changes may be made.

Full log


Message #8 received at 41850 <at> debbugs.gnu.org (full text, mbox):

From: Pádraig Brady <P <at> draigBrady.com>
To: Tobias Stoeckmann <tobias <at> stoeckmann.org>, 41850 <at> debbugs.gnu.org
Subject: Re: bug#41850: [PATCH] maint: Avoid signed integer overflows
Date: Mon, 15 Jun 2020 23:11:57 +0100
[Message part 1 (text/plain, inline)]
On 14/06/2020 13:47, Tobias Stoeckmann wrote:
> 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.

Thanks for fixing those -fsanitize=undefined issues.

I can confirm with GCC 10 -fsanitize=undefined was giving:

  src/numfmt.c:1505:31: runtime error:
  negation of -9223372036854775808 cannot be represented in type 'long int'

How did you notice BTW. This wasn't exposed in existing tests.
I've updated your patch (attached) to add tests for this.

cheers,
Pádraig
[numfmt-seq-ubsan.patch (text/x-patch, attachment)]

This bug report was last modified 3 years and 112 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.