Article View: gnu.gdb.bug
Article #8831GDB 4.7: integer overflow in constant expressions
From: Paul Eggert
Date: Sun, 25 Oct 1992 07:17
Date: Sun, 25 Oct 1992 07:17
254 lines
9855 bytes
9855 bytes
GDB 4.7 contains several instances of integer overflow in constant expressions.
Here are some generic examples of the kinds of problems involved.
int x = UINT_MAX; /* this number is too big for int */
int x = 0x82007ee0; /* ditto */
char x = (unsigned char)0x80; /* the right side evaluates to 128,
which is too big for signed char */
Strictly speaking, these examples do not conform to the ANSI C standard; some
compilers generate warnings about them. Here are the warning messages
generated by my compiler (GCC 2.3 hacked pre-release, SunOS 4.1.2, sparc) when
compiling GDB 4.7:
coffcode.h:3333: warning: signed integer overflow in constant expression
coffcode.h:3334: warning: signed integer overflow in constant expression
coffcode.h:3335: warning: signed integer overflow in constant expression
coffcode.h:3336: warning: signed integer overflow in constant expression
coffcode.h:3337: warning: signed integer overflow in constant expression
coffcode.h:3338: warning: signed integer overflow in constant expression
coffcode.h:3339: warning: signed integer overflow in constant expression
coffcode.h:3340: warning: signed integer overflow in constant expression
coffcode.h:3341: warning: signed integer overflow in constant expression
coffcode.h:3342: warning: signed integer overflow in constant expression
coffcode.h:3343: warning: signed integer overflow in constant expression
command.c:1059: warning: signed integer overflow in constant expression
ieee-float.c:86: warning: signed integer overflow in constant expression
main.c:2193: warning: signed integer overflow in constant expression
mmcheck.c:104: warning: signed integer overflow in constant expression
mmcheck.c:133: warning: signed integer overflow in constant expression
mmcheck.c:63: warning: signed integer overflow in constant expression
sparc-tdep.c:233: warning: signed integer overflow in constant expression
sparc-tdep.c:282: warning: signed integer overflow in constant expression
valops.c:697: warning: signed integer overflow in constant expression
Here is a patch. This patch changes gdb/tm-sparc.h so that REGISTER_TYPE is
an unsigned type (so that large hexadecimal constants can be used with it);
most of the other tm-*.h files probably need to be patched similarly, but I've
omitted those patches here.
===================================================================
RCS file: gdb/command.c,v
retrieving revision 4.7
diff -c -r4.7 gdb/command.c
*** gdb/command.c 1992/10/16 19:16:45 4.7
--- gdb/command.c 1992/10/25 07:02:26
***************
*** 1055,1062 ****
if (arg == NULL)
error_no_arg ("integer to set it to.");
*(int *) c->var = parse_and_eval_address (arg);
! if (*(int *) c->var == 0)
! *(int *) c->var = UINT_MAX;
break;
case var_zinteger:
if (arg == NULL)
--- 1055,1062 ----
if (arg == NULL)
error_no_arg ("integer to set it to.");
*(int *) c->var = parse_and_eval_address (arg);
! if (*(unsigned int *) c->var == 0)
! *(unsigned int *) c->var = UINT_MAX;
break;
case var_zinteger:
if (arg == NULL)
===================================================================
RCS file: gdb/ieee-float.c,v
retrieving revision 4.7
diff -c -r4.7 gdb/ieee-float.c
*** gdb/ieee-float.c 1992/07/06 17:10:52 4.7
--- gdb/ieee-float.c 1992/10/25 07:02:26
***************
*** 82,89 ****
return; /* Result is zero */
if (dfrom != dfrom) {
/* From is NaN */
! to[EXPBYTE_H] = (unsigned char)(EXT_EXP_NAN >> 8);
! to[EXPBYTE_L] = (unsigned char)EXT_EXP_NAN;
to[MANBYTE_H] = 1; /* Be sure it's not infinity, but NaN value is irrel */
return; /* Result is NaN */
}
--- 82,89 ----
return; /* Result is zero */
if (dfrom != dfrom) {
/* From is NaN */
! ((unsigned char *)to)[EXPBYTE_H] = EXT_EXP_NAN >> 8;
! ((unsigned char *)to)[EXPBYTE_L] = EXT_EXP_NAN;
to[MANBYTE_H] = 1; /* Be sure it's not infinity, but NaN value is irrel */
return; /* Result is NaN */
}
===================================================================
RCS file: gdb/main.c,v
retrieving revision 4.7
diff -c -r4.7 gdb/main.c
*** gdb/main.c 1992/10/08 00:30:49 4.7
--- gdb/main.c 1992/10/25 07:02:26
***************
*** 2189,2198 ****
else if (history_size >= 0)
stifle_history (history_size);
else
! {
! history_size = UINT_MAX;
! error ("History size must be non-negative");
! }
}
/* ARGSUSED */
--- 2189,2195 ----
else if (history_size >= 0)
stifle_history (history_size);
else
! error ("History size must be non-negative");
}
/* ARGSUSED */
===================================================================
RCS file: gdb/sparc-tdep.c,v
retrieving revision 4.7
diff -c -r4.7 gdb/sparc-tdep.c
*** gdb/sparc-tdep.c 1992/10/23 03:54:17 4.7
--- gdb/sparc-tdep.c 1992/10/25 07:02:26
***************
*** 228,234 ****
* original contents of g1. A * indicates that the actual value of
* the instruction is modified below.
*/
! static int save_insn_opcodes[] = {
0x03000000, 0x82007ee0, 0x9de38001, 0x03000000,
0x82007ee0, 0x91d02001, 0x01000000 };
--- 228,234 ----
* original contents of g1. A * indicates that the actual value of
* the instruction is modified below.
*/
! static unsigned int save_insn_opcodes[] = {
0x03000000, 0x82007ee0, 0x9de38001, 0x03000000,
0x82007ee0, 0x91d02001, 0x01000000 };
***************
*** 279,285 ****
t %g0,1
sethi %hi(0),%g0 */
! static int restore_insn_opcodes[] = { 0x81e80000, 0x91d02001, 0x01000000 };
static void
do_restore_insn ()
--- 279,286 ----
t %g0,1
sethi %hi(0),%g0 */
! static unsigned int restore_insn_opcodes[] = {
! 0x81e80000, 0x91d02001, 0x01000000 };
static void
do_restore_insn ()
===================================================================
RCS file: gdb/tm-sparc.h,v
retrieving revision 4.7
diff -c -r4.7 gdb/tm-sparc.h
*** gdb/tm-sparc.h 1992/09/25 22:59:23 4.7
--- gdb/tm-sparc.h 1992/10/25 07:02:26
***************
*** 113,119 ****
/* Say how long (ordinary) registers are. */
! #define REGISTER_TYPE long
/* Number of machine registers */
--- 113,119 ----
/* Say how long (ordinary) registers are. */
! #define REGISTER_TYPE unsigned long
/* Number of machine registers */
===================================================================
RCS file: include/coff/internal.h,v
retrieving revision 4.7
diff -c -r4.7 include/coff/internal.h
*** include/coff/internal.h 1992/09/30 17:57:07 4.7
--- include/coff/internal.h 1992/10/25 07:02:26
***************
*** 121,141 ****
#define C_EINCL 109 /* Marks ending of include file */
/* storage classes for stab symbols for RS/6000 */
! #define C_GSYM ((signed char)0x80)
! #define C_LSYM ((signed char)0x81)
! #define C_PSYM ((signed char)0x82)
! #define C_RSYM ((signed char)0x83)
! #define C_RPSYM ((signed char)0x84)
! #define C_STSYM ((signed char)0x85)
! #define C_TCSYM ((signed char)0x86)
! #define C_BCOMM ((signed char)0x87)
! #define C_ECOML ((signed char)0x88)
! #define C_ECOMM ((signed char)0x89)
! #define C_DECL ((signed char)0x8c)
! #define C_ENTRY ((signed char)0x8d)
! #define C_FUN ((signed char)0x8e)
! #define C_BSTAT ((signed char)0x8f)
! #define C_ESTAT ((signed char)0x90)
/********************** SECTION HEADER **********************/
struct internal_scnhdr {
--- 121,141 ----
#define C_EINCL 109 /* Marks ending of include file */
/* storage classes for stab symbols for RS/6000 */
! #define C_GSYM '\200'
! #define C_LSYM '\201'
! #define C_PSYM '\202'
! #define C_RSYM '\203'
! #define C_RPSYM '\204'
! #define C_STSYM '\205'
! #define C_TCSYM '\206'
! #define C_BCOMM '\207'
! #define C_ECOML '\210'
! #define C_ECOMM '\211'
! #define C_DECL '\212'
! #define C_ENTRY '\213'
! #define C_FUN '\214'
! #define C_BSTAT '\215'
! #define C_ESTAT '\220'
/********************** SECTION HEADER **********************/
struct internal_scnhdr {
===================================================================
RCS file: mmalloc/mmcheck.c,v
retrieving revision 4.7
diff -c -r4.7 mmalloc/mmcheck.c
*** mmalloc/mmcheck.c 1992/04/17 03:01:49 4.7
--- mmalloc/mmcheck.c 1992/10/25 07:02:26
***************
*** 34,40 ****
#define MAGICWORD (unsigned int) 0xfedabeeb /* Active chunk */
#define MAGICWORDFREE (unsigned int) 0xdeadbeef /* Inactive chunk */
! #define MAGICBYTE ((char) 0xd7)
/* Each memory allocation is bounded by a header structure and a trailer
byte. I.E.
--- 34,40 ----
#define MAGICWORD (unsigned int) 0xfedabeeb /* Active chunk */
#define MAGICWORDFREE (unsigned int) 0xdeadbeef /* Inactive chunk */
! #define MAGICBYTE '\327'
/* Each memory allocation is bounded by a header structure and a trailer
byte. I.E.
Technical Details
Message-ID:
<9210250717.AA08622@bi.twinsun.com>Path:
arc1-ca.pugleaf.net!sparky!uunet!usc!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!bi.TWinsun.COM!eggertShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f5053,6b5034437d1da4d1,start X-Google-Attributes: gidf5053,public X-Google-ArrivalTime: 1992-10-25 13:51:44 PST Newsgroups: gnu.gdb.bug Path: arc1-ca.pugleaf.net!sparky!uunet!usc!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!bi.TWinsun.COM!eggert From: eggert@bi.TWinsun.COM (Paul Eggert) Subject: GDB 4.7: integer overflow in constant expressions Message-ID: <9210250717.AA08622@bi.twinsun.com> Sender: gnulists@ai.mit.edu Organization: GNUs Not Usenet Distribution: gnu Date: Sun, 25 Oct 1992 07:17:16 GMT Approved: bug-gdb@prep.ai.mit.edu Lines: 255