Mercurial > cpython-lru_cache-weakref
diff Python/bltinmodule.c @ 7678:4030059cf97c legacy-trunk
Use a faster way to check for null bytes in the string argument for
int(), long(), float().
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Fri, 13 Mar 1998 21:30:14 +0000 |
| parents | d85147dce185 |
| children | a909a2869ac5 |
line wrap: on
line diff
--- a/Python/bltinmodule.c Fri Mar 13 20:12:17 1998 +0000 +++ b/Python/bltinmodule.c Fri Mar 13 21:30:14 1998 +0000 @@ -2095,8 +2095,7 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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);
