Module Name: src
Committed By: dsl
Date: Sun Aug 2 21:24:18 UTC 2009
Modified Files:
src/bin/ksh: var.c
Log Message:
Support 0xnn for hexadecimal constants - as well as 16#nn.
While here, make '-' only valid once, and at the start of the number.
Fixes PR/40512
To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/bin/ksh/var.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/bin/ksh/var.c
diff -u src/bin/ksh/var.c:1.14 src/bin/ksh/var.c:1.15
--- src/bin/ksh/var.c:1.14 Wed Mar 29 15:51:00 2006
+++ src/bin/ksh/var.c Sun Aug 2 21:24:18 2009
@@ -1,9 +1,9 @@
-/* $NetBSD: var.c,v 1.14 2006/03/29 15:51:00 christos Exp $ */
+/* $NetBSD: var.c,v 1.15 2009/08/02 21:24:18 dsl Exp $ */
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: var.c,v 1.14 2006/03/29 15:51:00 christos Exp $");
+__RCSID("$NetBSD: var.c,v 1.15 2009/08/02 21:24:18 dsl Exp $");
#endif
@@ -458,10 +458,17 @@
base = 10;
num = 0;
neg = 0;
+ if (*s == '-') {
+ neg = 1;
+ s++;
+ }
+ if (s[0] == '0' && s[1] == 'x') {
+ base = 16;
+ have_base = 1;
+ s += 2;
+ }
for (c = (unsigned char)*s++; c ; c = (unsigned char)*s++) {
- if (c == '-') {
- neg++;
- } else if (c == '#') {
+ if (c == '#') {
base = (int) num;
if (have_base || base < 2 || base > 36)
return -1;