summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2014-01-10 23:01:30 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2014-01-10 23:01:30 +0000
commit9fa2506e5a465739b0ac642d8a566f9b00b937ef (patch)
treea489a5dcd5beceb973675742606653c19abc6635 /usr.bin
parent88d5a9850924c40640403be488d99c75e12237e0 (diff)
Use strtoul() to do octal and hex character conversion instead of
custom code.
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/yacc/defs.h3
-rw-r--r--usr.bin/yacc/reader.c55
2 files changed, 12 insertions, 46 deletions
diff --git a/usr.bin/yacc/defs.h b/usr.bin/yacc/defs.h
index 1817db7d075..a67a399d3a4 100644
--- a/usr.bin/yacc/defs.h
+++ b/usr.bin/yacc/defs.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: defs.h,v 1.15 2014/01/08 23:12:57 millert Exp $ */
+/* $OpenBSD: defs.h,v 1.16 2014/01/10 23:01:29 millert Exp $ */
/* $NetBSD: defs.h,v 1.6 1996/03/19 03:21:30 jtc Exp $ */
/*
@@ -125,7 +125,6 @@
/* character macros */
#define IS_IDENT(c) (isalnum(c) || (c) == '_' || (c) == '.' || (c) == '$')
-#define IS_OCTAL(c) ((c) >= '0' && (c) <= '7')
#define NUMERIC_VALUE(c) ((c) - '0')
diff --git a/usr.bin/yacc/reader.c b/usr.bin/yacc/reader.c
index f585440ebf3..5fb6ea09dca 100644
--- a/usr.bin/yacc/reader.c
+++ b/usr.bin/yacc/reader.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: reader.c,v 1.25 2014/01/08 22:55:59 millert Exp $ */
+/* $OpenBSD: reader.c,v 1.26 2014/01/10 23:01:29 millert Exp $ */
/* $NetBSD: reader.c,v 1.5 1996/03/19 03:21:43 jtc Exp $ */
/*
@@ -75,7 +75,6 @@ int keyword(void);
void copy_ident(void);
void copy_text(void);
void copy_union(void);
-int hexval(int);
bucket * get_literal(void);
int is_reserved(char *);
bucket * get_name(void);
@@ -653,19 +652,6 @@ loop:
}
-int
-hexval(int c)
-{
- if (c >= '0' && c <= '9')
- return (c - '0');
- if (c >= 'A' && c <= 'F')
- return (c - 'A' + 10);
- if (c >= 'a' && c <= 'f')
- return (c - 'a' + 10);
- return (-1);
-}
-
-
bucket *
get_literal(void)
{
@@ -688,6 +674,7 @@ get_literal(void)
if (c == '\\')
{
char *c_cptr = cptr - 1;
+ unsigned long ulval;
c = (unsigned char)*cptr++;
switch (c)
@@ -699,38 +686,18 @@ get_literal(void)
case '0': case '1': case '2': case '3':
case '4': case '5': case '6': case '7':
- n = c - '0';
- c = (unsigned char)*cptr;
- if (IS_OCTAL(c))
- {
- n = (n << 3) + (c - '0');
- c = (unsigned char)*++cptr;
- if (IS_OCTAL(c))
- {
- n = (n << 3) + (c - '0');
- ++cptr;
- }
- }
- if (n > MAXCHAR) illegal_character(c_cptr);
- c = n;
+ ulval = strtoul(cptr - 1, &s, 8);
+ if (s == cptr - 1 || ulval > MAXCHAR) illegal_character(c_cptr);
+ c = (int)ulval;
+ cptr = s;
break;
case 'x':
- c = (unsigned char)*cptr++;
- n = hexval(c);
- if (n < 0 || n >= 16)
- illegal_character(c_cptr);
- for (;;)
- {
- c = (unsigned char)*cptr;
- i = hexval(c);
- if (i < 0 || i >= 16) break;
- ++cptr;
- n = (n << 4) + i;
- if (n > MAXCHAR) illegal_character(c_cptr);
- }
- c = n;
- break;
+ ulval = strtoul(cptr, &s, 16);
+ if (s == cptr || ulval > MAXCHAR) illegal_character(c_cptr);
+ c = (int)ulval;
+ cptr = s;
+ break;
case 'a': c = 7; break;
case 'b': c = '\b'; break;