diff Objects/unicodeobject.c @ 12629:3efeaa7521e4 legacy-trunk

Trent Mick: Fix the string methods that implement slice-like semantics with optional args (count, find, endswith, etc.) to properly handle indeces outside [INT_MIN, INT_MAX]. Previously the "i" formatter for PyArg_ParseTuple was used to get the indices. These could overflow. This patch changes the string methods to use the "O&" formatter with the slice_index() function from ceval.c which is used to do the same job for Python code slices (e.g. 'abcabcabc'[0:1000000000L]).
author Guido van Rossum <guido@python.org>
date Tue, 09 May 2000 14:14:27 +0000
parents 0bab1e36a3a6
children c4eb70d24a87
line wrap: on
line diff
--- a/Objects/unicodeobject.c	Tue May 09 10:56:00 2000 +0000
+++ b/Objects/unicodeobject.c	Tue May 09 14:14:27 2000 +0000
@@ -3023,7 +3023,8 @@
     int end = INT_MAX;
     PyObject *result;
 
-    if (!PyArg_ParseTuple(args, "O|ii:count", &substring, &start, &end))
+    if (!PyArg_ParseTuple(args, "O|O&O&:count", &substring,
+		_PyEval_SliceIndex, &start, _PyEval_SliceIndex, &end))
         return NULL;
 
     substring = (PyUnicodeObject *)PyUnicode_FromObject(
@@ -3150,7 +3151,8 @@
     int end = INT_MAX;
     PyObject *result;
 
-    if (!PyArg_ParseTuple(args, "O|ii:find", &substring, &start, &end))
+    if (!PyArg_ParseTuple(args, "O|O&O&:find", &substring,
+		_PyEval_SliceIndex, &start, _PyEval_SliceIndex, &end))
         return NULL;
     substring = (PyUnicodeObject *)PyUnicode_FromObject(
 						(PyObject *)substring);
@@ -3212,7 +3214,8 @@
     int start = 0;
     int end = INT_MAX;
 
-    if (!PyArg_ParseTuple(args, "O|ii:index", &substring, &start, &end))
+    if (!PyArg_ParseTuple(args, "O|O&O&:index", &substring,
+		_PyEval_SliceIndex, &start, _PyEval_SliceIndex, &end))
         return NULL;
     
     substring = (PyUnicodeObject *)PyUnicode_FromObject(
@@ -3642,7 +3645,8 @@
     int end = INT_MAX;
     PyObject *result;
 
-    if (!PyArg_ParseTuple(args, "O|ii:rfind", &substring, &start, &end))
+    if (!PyArg_ParseTuple(args, "O|O&O&:rfind", &substring,
+		_PyEval_SliceIndex, &start, _PyEval_SliceIndex, &end))
         return NULL;
     substring = (PyUnicodeObject *)PyUnicode_FromObject(
 						(PyObject *)substring);
@@ -3668,7 +3672,8 @@
     int start = 0;
     int end = INT_MAX;
 
-    if (!PyArg_ParseTuple(args, "O|ii:rindex", &substring, &start, &end))
+    if (!PyArg_ParseTuple(args, "O|O&O&:rindex", &substring,
+		_PyEval_SliceIndex, &start, _PyEval_SliceIndex, &end))
         return NULL;
     substring = (PyUnicodeObject *)PyUnicode_FromObject(
 						(PyObject *)substring);
@@ -3937,7 +3942,8 @@
     int end = INT_MAX;
     PyObject *result;
 
-    if (!PyArg_ParseTuple(args, "O|ii:startswith", &substring, &start, &end))
+    if (!PyArg_ParseTuple(args, "O|O&O&:startswith", &substring,
+		_PyEval_SliceIndex, &start, _PyEval_SliceIndex, &end))
 	return NULL;
     substring = (PyUnicodeObject *)PyUnicode_FromObject(
 						(PyObject *)substring);
@@ -3967,7 +3973,8 @@
     int end = INT_MAX;
     PyObject *result;
 
-    if (!PyArg_ParseTuple(args, "O|ii:endswith", &substring, &start, &end))
+    if (!PyArg_ParseTuple(args, "O|O&O&:endswith", &substring,
+		_PyEval_SliceIndex, &start, _PyEval_SliceIndex, &end))
 	return NULL;
     substring = (PyUnicodeObject *)PyUnicode_FromObject(
 						(PyObject *)substring);