[Python-checkins] r81820 - in python/trunk: Lib/test/test_unicode.py Misc/NEWS Objects/stringlib/string_format.h
benjamin.peterson
python-checkins at python.org
Tue Jun 8 00:23:23 CEST 2010
Author: benjamin.peterson
Date: Tue Jun 8 00:23:23 2010
New Revision: 81820
Log:
correctly overflow when indexes are too large
Modified:
python/trunk/Lib/test/test_unicode.py
python/trunk/Misc/NEWS
python/trunk/Objects/stringlib/string_format.h
Modified: python/trunk/Lib/test/test_unicode.py
==============================================================================
--- python/trunk/Lib/test/test_unicode.py (original)
+++ python/trunk/Lib/test/test_unicode.py Tue Jun 8 00:23:23 2010
@@ -1282,6 +1282,9 @@
self.assertRaises(IndexError, u"{:}".format)
self.assertRaises(IndexError, u"{:s}".format)
self.assertRaises(IndexError, u"{}".format)
+ big = "23098475029384702983476098230754973209482573"
+ self.assertRaises(ValueError, ("{" + big + "}").format)
+ self.assertRaises(ValueError, ("{[" + big + "]}").format, [0])
# issue 6089
self.assertRaises(ValueError, u"{0[0]x}".format, [None])
Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS (original)
+++ python/trunk/Misc/NEWS Tue Jun 8 00:23:23 2010
@@ -12,6 +12,9 @@
Core and Builtins
-----------------
+- In the unicode/str.format(), raise a ValueError when either indexes to
+ arguments are too large.
+
Library
-------
Modified: python/trunk/Objects/stringlib/string_format.h
==============================================================================
--- python/trunk/Objects/stringlib/string_format.h (original)
+++ python/trunk/Objects/stringlib/string_format.h Tue Jun 8 00:23:23 2010
@@ -373,6 +373,8 @@
if (_FieldNameIterator_item(self, name) == 0)
return 0;
*name_idx = get_integer(name);
+ if (*name_idx == -1 && PyErr_Occurred())
+ return 0;
break;
default:
/* Invalid character follows ']' */
@@ -429,6 +431,8 @@
/* see if "first" is an integer, in which case it's used as an index */
*first_idx = get_integer(first);
+ if (*first_idx == -1 && PyErr_Occurred())
+ return 0;
field_name_is_empty = first->ptr >= first->end;
More information about the Python-checkins
mailing list