summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorNeal Norwitz <nnorwitz@gmail.com>2006-08-13 18:11:08 (GMT)
committerNeal Norwitz <nnorwitz@gmail.com>2006-08-13 18:11:08 (GMT)
commit56423e5762fc7eef66da0f04baa59c185c79ca81 (patch)
tree64da4b88537ce4addbdaf3b017253d7e3ebd9777 /Objects
parent3cb31ac704c98fa8a5b9e31a3bd4a8f25bf3d679 (diff)
downloadcpython-56423e5762fc7eef66da0f04baa59c185c79ca81.zip
cpython-56423e5762fc7eef66da0f04baa59c185c79ca81.tar.gz
cpython-56423e5762fc7eef66da0f04baa59c185c79ca81.tar.bz2
Fix segfault when doing string formatting on subclasses of long if
__oct__, __hex__ don't return a string. Klocwork 308
Diffstat (limited to 'Objects')
-rw-r--r--Objects/stringobject.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/Objects/stringobject.c b/Objects/stringobject.c
index bbbeaa6..2189a82 100644
--- a/Objects/stringobject.c
+++ b/Objects/stringobject.c
@@ -4225,12 +4225,15 @@ _PyString_FormatLong(PyObject *val, int flags, int prec, int type,
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);
llen = PyString_Size(result);
if (llen > PY_SSIZE_T_MAX) {
PyErr_SetString(PyExc_ValueError, "string too large in _PyString_FormatLong");