Simplify code parsing integers and, in process fix a -Wuninitialized warning.

This commit is contained in:
Andrew Cagney 2001-02-16 01:27:46 +00:00
parent 9afc4bbfbb
commit 0f6e1ba6ee
2 changed files with 21 additions and 16 deletions

View File

@ -1,3 +1,8 @@
2001-02-15 Andrew Cagney <ac131313@redhat.com>
* f-exp.y: Include <ctype.h>.
(parse_number): Ensure that ``i'' is always initialized.
2001-02-14 Jim Kingdon <jkingdon@engr.sgi.com> 2001-02-14 Jim Kingdon <jkingdon@engr.sgi.com>
* MAINTAINERS: Add myself to paper trail section. * MAINTAINERS: Add myself to paper trail section.

View File

@ -53,6 +53,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
#include "bfd.h" /* Required by objfiles.h. */ #include "bfd.h" /* Required by objfiles.h. */
#include "symfile.h" /* Required by objfiles.h. */ #include "symfile.h" /* Required by objfiles.h. */
#include "objfiles.h" /* For have_full_symbols and have_partial_symbols */ #include "objfiles.h" /* For have_full_symbols and have_partial_symbols */
#include <ctype.h>
/* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc), /* Remap normal yacc parser interface names (yyparse, yylex, yyerror, etc),
as well as gratuitiously global symbol names, so we can have multiple as well as gratuitiously global symbol names, so we can have multiple
@ -639,7 +640,6 @@ parse_number (p, len, parsed_float, putithere)
{ {
register LONGEST n = 0; register LONGEST n = 0;
register LONGEST prevn = 0; register LONGEST prevn = 0;
register int i;
register int c; register int c;
register int base = input_radix; register int base = input_radix;
int unsigned_p = 0; int unsigned_p = 0;
@ -697,26 +697,26 @@ parse_number (p, len, parsed_float, putithere)
while (len-- > 0) while (len-- > 0)
{ {
c = *p++; c = *p++;
if (c >= 'A' && c <= 'Z') if (isupper (c))
c += 'a' - 'A'; c = tolower (c);
if (c != 'l' && c != 'u') if (len == 0 && c == 'l')
n *= base; long_p = 1;
if (c >= '0' && c <= '9') else if (len == 0 && c == 'u')
n += i = c - '0'; unsigned_p = 1;
else else
{ {
if (base > 10 && c >= 'a' && c <= 'f') int i;
n += i = c - 'a' + 10; if (c >= '0' && c <= '9')
else if (len == 0 && c == 'l') i = c - '0';
long_p = 1; else if (c >= 'a' && c <= 'f')
else if (len == 0 && c == 'u') i = c - 'a' + 10;
unsigned_p = 1;
else else
return ERROR; /* Char not a digit */ return ERROR; /* Char not a digit */
if (i >= base)
return ERROR; /* Invalid digit in this base */
n *= base;
n += i;
} }
if (i >= base)
return ERROR; /* Invalid digit in this base */
/* Portably test for overflow (only works for nonzero values, so make /* Portably test for overflow (only works for nonzero values, so make
a second check for zero). */ a second check for zero). */
if ((prevn >= n) && n != 0) if ((prevn >= n) && n != 0)