[Python-checkins] cpython (2.7): disallow a negative idx parameter
benjamin.peterson
python-checkins at python.org
Mon Apr 14 17:52:22 CEST 2014
http://hg.python.org/cpython/rev/c095ff9b0e84
changeset: 90261:c095ff9b0e84
branch: 2.7
parent: 90255:f729a0e90c4f
user: Benjamin Peterson <benjamin at python.org>
date: Mon Apr 14 11:43:09 2014 -0400
summary:
disallow a negative idx parameter
files:
Modules/_json.c | 18 ++++++++++--------
1 files changed, 10 insertions(+), 8 deletions(-)
diff --git a/Modules/_json.c b/Modules/_json.c
--- a/Modules/_json.c
+++ b/Modules/_json.c
@@ -1468,10 +1468,11 @@
PyObject *res;
char *str = PyString_AS_STRING(pystr);
Py_ssize_t length = PyString_GET_SIZE(pystr);
- if (idx < 0)
- /* Compatibility with the Python version. */
- idx += length;
- if (idx < 0 || idx >= length) {
+ if (idx < 0) {
+ PyErr_SetString(PyExc_ValueError, "idx cannot be negative");
+ return NULL;
+ }
+ if (idx >= length) {
PyErr_SetNone(PyExc_StopIteration);
return NULL;
}
@@ -1558,10 +1559,11 @@
PyObject *res;
Py_UNICODE *str = PyUnicode_AS_UNICODE(pystr);
Py_ssize_t length = PyUnicode_GET_SIZE(pystr);
- if (idx < 0)
- /* Compatibility with Python version. */
- idx += length;
- if (idx < 0 || idx >= length) {
+ if (idx < 0) {
+ PyErr_SetString(PyExc_ValueError, "idx cannot be negative");
+ return NULL;
+ }
+ if (idx >= length) {
PyErr_SetNone(PyExc_StopIteration);
return NULL;
}
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list