This is the mail archive of the
gdb-prs@sources.redhat.com
mailing list for the GDB project.
gdb/181: off-by-one numeric literal error
- To: gdb-gnats at sources dot redhat dot com
- Subject: gdb/181: off-by-one numeric literal error
- From: dcoutts at cray dot com
- Date: 24 Jul 2001 21:08:57 -0000
- Reply-To: dcoutts at cray dot com
>Number: 181
>Category: gdb
>Synopsis: off-by-one numeric literal error
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Tue Jul 24 14:18:00 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator: dcoutts@cray.com
>Release: gdb 5.0
>Organization:
>Environment:
mips-sgi-irix6.5
>Description:
On a int=32bit machine, the number -2147483648 is overflowed
unless it is explicitly cast. It should not overflow, since
this is the most negative number that can be represented in
2's comp in 32 bits.
(gdb) p -2147483648
$63 = 2147483648
(gdb) p (int) -2147483648
$64 = -2147483648
Similar interesting results:
(long=64bit)
(gdb) p -9223372036854775808
$38 = 9223372036854775808
(gdb) p (long) -9223372036854775808
$39 = -9223372036854775808
(gdb) p 0x8000000000000000
$40 = 9223372036854775808
(gdb) p /x 0x8000000000000000
$41 = 0x8000000000000000
(gdb) p /x 9223372036854775808
$42 = 0x8000000000000000
(gdb) p /x -9223372036854775808
$43 = 0x8000000000000000
>How-To-Repeat:
on a 32 bit machine:
p -2147483648
>Fix:
use (-1 << 31) instead:
(gdb) p (-1 << 31)
$70 = -2147483648
>Release-Note:
>Audit-Trail:
>Unformatted: