[Python-checkins] r52160 - in python/branches/release24-maint: Lib/test/test_format.py Misc/NEWS Objects/stringobject.c
andrew.kuchling
python-checkins at python.org
Thu Oct 5 19:18:15 CEST 2006
Author: andrew.kuchling
Date: Thu Oct 5 19:18:13 2006
New Revision: 52160
Modified:
python/branches/release24-maint/Lib/test/test_format.py
python/branches/release24-maint/Misc/NEWS
python/branches/release24-maint/Objects/stringobject.c
Log:
[Backport r51248 | neal.norwitz]
Fix segfault when doing string formatting on subclasses of long if
__oct__, __hex__ don't return a string.
Klocwork 308
Modified: python/branches/release24-maint/Lib/test/test_format.py
==============================================================================
--- python/branches/release24-maint/Lib/test/test_format.py (original)
+++ python/branches/release24-maint/Lib/test/test_format.py Thu Oct 5 19:18:13 2006
@@ -230,6 +230,14 @@
test_exc(u'no format', u'1', TypeError,
"not all arguments converted during string formatting")
+class Foobar(long):
+ def __oct__(self):
+ # Returning a non-string should not blow up.
+ return self + 1
+
+test_exc('%o', Foobar(), TypeError,
+ "expected string or Unicode object, long found")
+
if sys.maxint == 2**31-1:
# crashes 2.2.1 and earlier:
try:
Modified: python/branches/release24-maint/Misc/NEWS
==============================================================================
--- python/branches/release24-maint/Misc/NEWS (original)
+++ python/branches/release24-maint/Misc/NEWS Thu Oct 5 19:18:13 2006
@@ -30,7 +30,9 @@
- Fix memory leak of coding spec in Parser/tokenizer.c.
- Fix memory leak in file_init.
-
+
+- Fix segfault when doing string formatting on subclasses of long.
+
- Overflow checking code in integer division ran afoul of new gcc
optimizations. Changed to be more standard-conforming.
Modified: python/branches/release24-maint/Objects/stringobject.c
==============================================================================
--- python/branches/release24-maint/Objects/stringobject.c (original)
+++ python/branches/release24-maint/Objects/stringobject.c Thu Oct 5 19:18:13 2006
@@ -3665,12 +3665,15 @@
if (!result)
return NULL;
+ buf = PyString_AsString(result);
+ if (!buf)
+ return NULL;
+
/* To modify the string in-place, there can only be one reference. */
if (result->ob_refcnt != 1) {
PyErr_BadInternalCall();
return NULL;
}
- buf = PyString_AsString(result);
len = PyString_Size(result);
if (buf[len-1] == 'L') {
--len;
More information about the Python-checkins
mailing list