diff Objects/stringobject.c @ 40006:f6bbe8d6fa33 2.4

[Backport r51248 | neal.norwitz] Fix segfault when doing string formatting on subclasses of long if __oct__, __hex__ don't return a string. Klocwork 308
author Andrew M. Kuchling <amk@amk.ca>
date Thu, 05 Oct 2006 17:18:13 +0000
parents a9b1f404e88b
children 2a05ee4a23e0
line wrap: on
line diff
--- a/Objects/stringobject.c	Thu Oct 05 17:06:59 2006 +0000
+++ b/Objects/stringobject.c	Thu Oct 05 17:18:13 2006 +0000
@@ -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;