diff options
author | Neal Norwitz <nnorwitz@gmail.com> | 2006-08-13 18:11:08 +0000 |
---|---|---|
committer | Neal Norwitz <nnorwitz@gmail.com> | 2006-08-13 18:11:08 +0000 |
commit | 56423e5762fc7eef66da0f04baa59c185c79ca81 (patch) | |
tree | 64da4b88537ce4addbdaf3b017253d7e3ebd9777 /Objects/stringobject.c | |
parent | 3cb31ac704c98fa8a5b9e31a3bd4a8f25bf3d679 (diff) | |
download | cpython-git-56423e5762fc7eef66da0f04baa59c185c79ca81.tar.gz |
Fix segfault when doing string formatting on subclasses of long if
__oct__, __hex__ don't return a string.
Klocwork 308
Diffstat (limited to 'Objects/stringobject.c')
-rw-r--r-- | Objects/stringobject.c | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/Objects/stringobject.c b/Objects/stringobject.c index bbbeaa6c0a..2189a8209f 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"); |