diff Python/compile.c @ 6501:9ef9cadd978c legacy-trunk

Don't use sscanf(s, "%x", &c) to parse \xX... escapes; hardcode it.
author Guido van Rossum <guido@python.org>
date Mon, 20 Oct 1997 23:24:07 +0000
parents c9b139b9c5ff
children ad114620f8c2
line wrap: on
line diff
--- a/Python/compile.c	Mon Oct 20 23:22:07 1997 +0000
+++ b/Python/compile.c	Mon Oct 20 23:24:07 1997 +0000
@@ -36,7 +36,6 @@
    XXX   (it's currently the first item of the co_const tuple)
    XXX Generate simple jump for break/return outside 'try...finally'
    XXX Allow 'continue' inside try-finally
-   XXX New 1-byte opcode for loading None
    XXX New opcode for loading the initial index for a for loop
    XXX other JAR tricks?
 */
@@ -922,11 +921,19 @@
 			break;
 		case 'x':
 			if (isxdigit(Py_CHARMASK(*s))) {
-				sscanf(s, "%x", &c);
-				*p++ = c;
+				unsigned int x = 0;
 				do {
+					c = Py_CHARMASK(*s);
 					s++;
+					x = (x<<4) & ~0xF;
+					if (isdigit(c))
+						x += c - '0';
+					else if (islower(c))
+						x += 10 + c - 'a';
+					else
+						x += 10 + c - 'A';
 				} while (isxdigit(Py_CHARMASK(*s)));
+				*p++ = x;
 				break;
 			}
 		/* FALLTHROUGH */