This is the mail archive of the gdb-prs@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

gdb/181: off-by-one numeric literal error



>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:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]