about summary refs log tree commit diff
path: root/Src
diff options
context:
space:
mode:
Diffstat (limited to 'Src')
-rw-r--r--Src/math.c37
-rw-r--r--Src/params.c9
2 files changed, 30 insertions, 16 deletions
diff --git a/Src/math.c b/Src/math.c
index 38466ed8e..77c7df2a5 100644
--- a/Src/math.c
+++ b/Src/math.c
@@ -342,21 +342,34 @@ zzlex(void)
 	    return EOI;
 	case '[':
 	    {
-		int base, setradix = 0;
-		if (*ptr == '#') {
-		    ptr++;
-		    setradix = 1;
-		}
-		base = zstrtol(ptr, &ptr, 10);
+		int n;
 
-		if (*ptr == ']')
-		    ptr++;
-		if (setradix)
-		    outputradix = base;
-		else {
-		    yyval.u.l = zstrtol(ptr, &ptr, lastbase = base);
+		if (idigit(*ptr)) {
+		    n = zstrtol(ptr, &ptr, 10);
+		    if (*ptr != ']' || !idigit(*++ptr)) {
+			zerr("bad base syntax", NULL, 0);
+			return EOI;
+		    }
+		    yyval.u.l = zstrtol(ptr, &ptr, lastbase = n);
 		    return NUM;
 		}
+		if (*ptr == '#') {
+		    n = 1;
+		    if (*++ptr == '#') {
+			n = -1;
+			ptr++;
+		    }
+		    if (!idigit(*ptr))
+			goto bofs;
+		    outputradix = n * zstrtol(ptr, &ptr, 10);
+		} else {
+		    bofs:
+		    zerr("bad output format specification", NULL, 0);
+		    return EOI;
+		}
+		if(*ptr != ']')
+			goto bofs;
+		ptr++;
 		break;
 	    }
 	case ' ':
diff --git a/Src/params.c b/Src/params.c
index 1439e9af8..2d38272a6 100644
--- a/Src/params.c
+++ b/Src/params.c
@@ -3041,10 +3041,10 @@ convbase(char *s, zlong v, int base)
 
     if (v < 0)
 	*s++ = '-', v = -v;
-    if (base <= 1)
-	base = 10;
+    if (base >= -1 && base <= 1)
+	base = -10;
 
-    if (base != 10) {
+    if (base > 0) {
 	if (isset(CBASES) && base == 16)
 	    sprintf(s, "0x");
 	else if (isset(CBASES) && base == 8 && isset(OCTALZEROES))
@@ -3052,7 +3052,8 @@ convbase(char *s, zlong v, int base)
 	else
 	    sprintf(s, "%d#", base);
 	s += strlen(s);
-    }
+    } else
+	base = -base;
     for (x = v; x; digs++)
 	x /= base;
     if (!digs)