From 8f74571596e23a1742d393532968cd727771c535 Mon Sep 17 00:00:00 2001
From: Guido van Rossum <guido@python.org>
Date: Fri, 13 Mar 1998 21:30:14 +0000
Subject: Use a faster way to check for null bytes in the string argument for
 int(), long(), float().

---
 Python/bltinmodule.c | 25 ++++++++++++++++++-------
 1 file changed, 18 insertions(+), 7 deletions(-)

diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index 3460f1a..87005f5 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -2095,8 +2095,7 @@ int_from_string(v)
 	long x;
 	char buffer[256]; /* For errors */
 
-	if (!PyArg_Parse(v, "s", &s))
-		return NULL;
+	s = PyString_AS_STRING(v);
 	while (*s && isspace(Py_CHARMASK(*s)))
 		s++;
 	if (s[0] == '\0') {
@@ -2112,6 +2111,11 @@ int_from_string(v)
 		PyErr_SetString(PyExc_ValueError, buffer);
 		return NULL;
 	}
+	else if (end-s != PyString_GET_SIZE(v)) {
+		PyErr_SetString(PyExc_ValueError,
+				"null byte in argument for int()");
+		return NULL;
+	}
 	else if (errno != 0) {
 		sprintf(buffer, "int() literal too large: %.200s", s);
 		PyErr_SetString(PyExc_ValueError, buffer);
@@ -2128,9 +2132,7 @@ long_from_string(v)
 	PyObject *x;
 	char buffer[256]; /* For errors */
 
-	if (!PyArg_Parse(v, "s", &s))
-		return NULL;
-
+	s = PyString_AS_STRING(v);
 	while (*s && isspace(Py_CHARMASK(*s)))
 		s++;
 	if (s[0] == '\0') {
@@ -2148,6 +2150,11 @@ long_from_string(v)
 		Py_DECREF(x);
 		return NULL;
 	}
+	else if (end-s != PyString_GET_SIZE(v)) {
+		PyErr_SetString(PyExc_ValueError,
+				"null byte in argument for float()");
+		return NULL;
+	}
 	return x;
 }
 
@@ -2160,8 +2167,7 @@ float_from_string(v)
 	double x;
 	char buffer[256]; /* For errors */
 
-	if (!PyArg_Parse(v, "s", &s))
-		return NULL;
+	s = PyString_AS_STRING(v);
 	while (*s && isspace(Py_CHARMASK(*s)))
 		s++;
 	if (s[0] == '\0') {
@@ -2179,6 +2185,11 @@ float_from_string(v)
 		PyErr_SetString(PyExc_ValueError, buffer);
 		return NULL;
 	}
+	else if (end-s != PyString_GET_SIZE(v)) {
+		PyErr_SetString(PyExc_ValueError,
+				"null byte in argument for float()");
+		return NULL;
+	}
 	else if (errno != 0) {
 		sprintf(buffer, "float() literal too large: %.200s", s);
 		PyErr_SetString(PyExc_ValueError, buffer);
-- 
cgit v0.12

