Bug#903771: c99: buggy POSIX abs(INT_MIN)
Package: gcc
Version: 4:7.3.0-3
Severity: normal
In the new POSIX abs() specification:
If the result cannot be represented, the result shall be {INT_MIN}.
instead of being undefined behavior. See:
http://austingroupbugs.net/view.php?id=1108#c4041
Thus the following program
----------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
int main (void)
{
volatile int i = INT_MIN;
int j;
j = abs (i);
printf ("%d %d\n", j, j >= 0);
return 0;
}
----------------------------------------
should output -2147483648 0 when compiled with the c99 utility. But:
zira:~> c99 -O2 -o tst tst.c
zira:~> ./tst
-2147483648 1
-- System Information:
Debian Release: buster/sid
APT prefers unstable-debug
APT policy: (500, 'unstable-debug'), (500, 'stable-updates'), (500, 'unstable'), (500, 'testing'), (500, 'stable'), (1, 'experimental')
Architecture: amd64 (x86_64)
Kernel: Linux 4.16.0-2-amd64 (SMP w/8 CPU cores)
Locale: LANG=POSIX, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8), LANGUAGE=POSIX (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)
LSM: AppArmor: enabled
Versions of packages gcc depends on:
ii cpp 4:7.3.0-3
ii gcc-7 7.3.0-25
Versions of packages gcc recommends:
ii libc6-dev [libc-dev] 2.27-4
Versions of packages gcc suggests:
ii autoconf 2.69-11+local1
ii automake 1:1.15.1-3.1
ii bison 2:3.0.4.dfsg-1+b1
pn flex <none>
ii gcc-doc 5:7.2.0-2
ii gcc-multilib 4:7.3.0-3
ii gdb 7.12-6+b2
ii libtool 2.4.6-2.1+local1
ii make 4.2.1-1.1
ii manpages-dev 4.16-1
-- no debconf information
Reply to: