- To: GDB Patches <gdb-patches at sourceware dot cygnus dot com>
- Subject: [rfa/rfc] f-exp.y -Wuninitialized fixes
- From: Andrew Cagney <ac131313 at cygnus dot com>
- Date: Mon, 27 Nov 2000 18:54:37 +1100
Hello,
I went to fix the -Wuninitialized warning in f-exp.y but couldn't
understand the underlying code. The attatched is an attempted cleanup
of the code handling number conversions.
Look OK? Can I trust the testsuite?
Andrew
* f-exp.y: Include <ctype.h>.
(parse_number): Ensure that ``i'' is always initialized.
Index: f-exp.y
===================================================================
RCS file: /cvs/src/src/gdb/f-exp.y,v
retrieving revision 1.2
diff -p -r1.2 f-exp.y
*** f-exp.y 2000/05/28 01:12:27 1.2
--- f-exp.y 2000/11/27 06:54:03
*************** Foundation, Inc., 59 Temple Place - Suit
*** 52,57 ****
--- 52,58 ----
#include "bfd.h" /* Required by objfiles.h. */
#include "symfile.h" /* Required by objfiles.h. */
#include "objfiles.h" /* For have_full_symbols and have_partial_symbols */
+ #include <ctype.h>
/* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc),
as well as gratuitiously global symbol names, so we can have multiple
*************** parse_number (p, len, parsed_float, puti
*** 638,644 ****
{
register LONGEST n = 0;
register LONGEST prevn = 0;
- register int i;
register int c;
register int base = input_radix;
int unsigned_p = 0;
--- 639,644 ----
*************** parse_number (p, len, parsed_float, puti
*** 696,721 ****
while (len-- > 0)
{
c = *p++;
! if (c >= 'A' && c <= 'Z')
! c += 'a' - 'A';
! if (c != 'l' && c != 'u')
! n *= base;
! if (c >= '0' && c <= '9')
! n += i = c - '0';
else
{
! if (base > 10 && c >= 'a' && c <= 'f')
! n += i = c - 'a' + 10;
! else if (len == 0 && c == 'l')
! long_p = 1;
! else if (len == 0 && c == 'u')
! unsigned_p = 1;
else
return ERROR; /* Char not a digit */
}
- if (i >= base)
- return ERROR; /* Invalid digit in this base */
-
/* Portably test for overflow (only works for nonzero values, so make
a second check for zero). */
if ((prevn >= n) && n != 0)
--- 696,721 ----
while (len-- > 0)
{
c = *p++;
! if (isupper (c))
! c = tolower (c);
! if (len == 0 && c == 'l')
! long_p = 1;
! else if (len == 0 && c == 'u')
! unsigned_p = 1;
else
{
! int i;
! if (c >= '0' && c <= '9')
! i = c - '0';
! else if (c >= 'a' && c <= 'f')
! i = c - 'a' + 10;
else
return ERROR; /* Char not a digit */
+ if (i >= base)
+ return ERROR; /* Invalid digit in this base */
+ n *= base;
+ n += i;
}
/* Portably test for overflow (only works for nonzero values, so make
a second check for zero). */
if ((prevn >= n) && n != 0)