shithub: mc

Download patch

ref: 285be77897e18d68efede25a98f423bddd4f2cb9
parent: 433357fe9fd4e99c70c780a0204244f5fd618cf2
author: Ori Bernstein <[email protected]>
date: Sun Sep 20 11:59:06 EDT 2020

Fix range checking for numbers.

--- a/lib/std/test/fmt.myr
+++ b/lib/std/test/fmt.myr
@@ -139,9 +139,9 @@
 	check(c, "77", "{w=?}", 77, (-1 : int8))
 	check(c, "77", "{w=?}", 77, (-1 : int16))
 	check(c, "77", "{w=?}", 77, (-1 : int32))
-	check(c, "77", "{w=?}", 77, (-4294967294 : int32))
+	check(c, "77", "{w=?}", 77, (-4294967294L : int32))
 	check(c, "77", "{w=?}", 77, (-1 : int64))
-	check(c, "77", "{w=?}", 77, (-18446744073709551614 : int64))
+	check(c, "77", "{w=?}", 77, (-18446744073709551614L : int64))
 	check(c, "77", "{w=?}", 77, (0 : int8))
 	check(c, "77", "{w=?}", 77, (0 : int16))
 	check(c, "77", "{w=?}", 77, (0 : int32))
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -2570,22 +2570,22 @@
 	int64_t sval;
 	uint64_t uval;
 	static const int64_t svranges[][2] = {
-		/* signed ints */
-		[Tyint8] = {-128LL, 127LL},
-		[Tyint16] = {-32768LL, 32767LL},
-		[Tyint32] = {-2147483648LL, 2147483647LL},
-		[Tyint] = {-2147483648LL, 2147483647LL},
-		[Tyint64] = {-9223372036854775808ULL, 9223372036854775807LL},
+		/* signed ints; allow one above max range for unary -'ve operator */
+		[Tyint8]  = {-128LL, 128LL},
+		[Tyint16] = {-32768LL, 32768LL},
+		[Tyint32] = {-2147483648LL, 2147483648LL},
+		[Tyint]	  = {-2147483648LL, 2147483648LL},
+		[Tyint64] = {-9223372036854775808ULL, 9223372036854775807ULL},
 	};
 
 	static const uint64_t uvranges[][2] = {
-		[Tybyte] = {0, 255ULL},
-		[Tyuint8] = {0, 255ULL},
+		[Tybyte]   = {0, 255ULL},
+		[Tyuint8]  = {0, 255ULL},
 		[Tyuint16] = {0, 65535ULL},
-		[Tyuint] = {0, 4294967295ULL},
+		[Tyuint]   = {0, 4294967295ULL},
 		[Tyuint32] = {0, 4294967295ULL},
 		[Tyuint64] = {0, 18446744073709551615ULL},
-		[Tychar] = {0, 4294967295ULL},
+		[Tychar]   = {0, 4294967295ULL},
 	};
 
 	/* signed types */
--- a/parse/tok.c
+++ b/parse/tok.c
@@ -732,6 +732,7 @@
 :
 		switch (peek()) {
 		case 'u':
+		case 'U':
 			if (unsignedval == 1)
 				lfatal(curloc, "Duplicate 'u' integer specifier");
 			next();
@@ -738,6 +739,7 @@
 			unsignedval = 1;
 			goto nextsuffix;
 		case 'l':
+		case 'L':
 			next();
 			if (unsignedval)
 				t->inttype = Tyuint64;
@@ -745,6 +747,7 @@
 				t->inttype = Tyint64;
 			break;
 		case 'i':
+		case 'I':
 			next();
 			if (unsignedval)
 				t->inttype = Tyuint32;
@@ -752,6 +755,7 @@
 				t->inttype = Tyint32;
 			break;
 		case 's':
+		case 'S':
 			next();
 			if (unsignedval)
 				t->inttype = Tyuint16;
@@ -759,6 +763,7 @@
 				t->inttype = Tyint16;
 			break;
 		case 'b':
+		case 'B':
 			next();
 			if (unsignedval)
 				t->inttype = Tyuint8;