mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
more _PyString_Resize error checking
This commit is contained in:
parent
3928276e64
commit
bea424af98
3 changed files with 20 additions and 13 deletions
|
@ -1102,8 +1102,8 @@ file_read(PyFileObject *f, PyObject *args)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (bytesread != buffersize)
|
if (bytesread != buffersize && _PyString_Resize(&v, bytesread))
|
||||||
_PyString_Resize(&v, bytesread);
|
return NULL;
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1356,8 +1356,8 @@ getline_via_fgets(PyFileObject *f, FILE *fp)
|
||||||
/* overwrite the trailing null byte */
|
/* overwrite the trailing null byte */
|
||||||
pvfree = BUF(v) + (prev_v_size - 1);
|
pvfree = BUF(v) + (prev_v_size - 1);
|
||||||
}
|
}
|
||||||
if (BUF(v) + total_v_size != p)
|
if (BUF(v) + total_v_size != p && _PyString_Resize(&v, p - BUF(v)))
|
||||||
_PyString_Resize(&v, p - BUF(v));
|
return NULL;
|
||||||
return v;
|
return v;
|
||||||
#undef INITBUFSIZE
|
#undef INITBUFSIZE
|
||||||
#undef MAXBUFSIZE
|
#undef MAXBUFSIZE
|
||||||
|
@ -1469,8 +1469,8 @@ get_line(PyFileObject *f, int n)
|
||||||
}
|
}
|
||||||
|
|
||||||
used_v_size = buf - BUF(v);
|
used_v_size = buf - BUF(v);
|
||||||
if (used_v_size != total_v_size)
|
if (used_v_size != total_v_size && _PyString_Resize(&v, used_v_size))
|
||||||
_PyString_Resize(&v, used_v_size);
|
return NULL;
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1536,8 +1536,10 @@ PyFile_GetLine(PyObject *f, int n)
|
||||||
"EOF when reading a line");
|
"EOF when reading a line");
|
||||||
}
|
}
|
||||||
else if (s[len-1] == '\n') {
|
else if (s[len-1] == '\n') {
|
||||||
if (result->ob_refcnt == 1)
|
if (result->ob_refcnt == 1) {
|
||||||
_PyString_Resize(&result, len-1);
|
if (_PyString_Resize(&result, len-1))
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
PyObject *v;
|
PyObject *v;
|
||||||
v = PyString_FromStringAndSize(s, len-1);
|
v = PyString_FromStringAndSize(s, len-1);
|
||||||
|
|
|
@ -1848,7 +1848,8 @@ encode_char:
|
||||||
if (inShift)
|
if (inShift)
|
||||||
*out++ = '-';
|
*out++ = '-';
|
||||||
|
|
||||||
_PyString_Resize(&v, out - start);
|
if (_PyString_Resize(&v, out - start))
|
||||||
|
return NULL;
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2169,7 +2170,8 @@ PyUnicode_EncodeUTF8(const Py_UNICODE *s,
|
||||||
/* Cut back to size actually needed. */
|
/* Cut back to size actually needed. */
|
||||||
nneeded = p - PyString_AS_STRING(v);
|
nneeded = p - PyString_AS_STRING(v);
|
||||||
assert(nneeded <= nallocated);
|
assert(nneeded <= nallocated);
|
||||||
_PyString_Resize(&v, nneeded);
|
if (_PyString_Resize(&v, nneeded))
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
return v;
|
return v;
|
||||||
|
|
||||||
|
@ -3129,7 +3131,8 @@ PyObject *unicodeescape_string(const Py_UNICODE *s,
|
||||||
*p++ = PyString_AS_STRING(repr)[1];
|
*p++ = PyString_AS_STRING(repr)[1];
|
||||||
|
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
_PyString_Resize(&repr, p - PyString_AS_STRING(repr));
|
if (_PyString_Resize(&repr, p - PyString_AS_STRING(repr)))
|
||||||
|
return NULL;
|
||||||
return repr;
|
return repr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3350,7 +3353,8 @@ PyObject *PyUnicode_EncodeRawUnicodeEscape(const Py_UNICODE *s,
|
||||||
*p++ = (char) ch;
|
*p++ = (char) ch;
|
||||||
}
|
}
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
_PyString_Resize(&repr, p - q);
|
if (_PyString_Resize(&repr, p - q))
|
||||||
|
return NULL;
|
||||||
return repr;
|
return repr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1237,7 +1237,8 @@ PyMarshal_WriteObjectToString(PyObject *x, int version)
|
||||||
"too much marshall data for a string");
|
"too much marshall data for a string");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
_PyString_Resize(&wf.str, (Py_ssize_t)(wf.ptr - base));
|
if (_PyString_Resize(&wf.str, (Py_ssize_t)(wf.ptr - base)))
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
if (wf.error != WFERR_OK) {
|
if (wf.error != WFERR_OK) {
|
||||||
Py_XDECREF(wf.str);
|
Py_XDECREF(wf.str);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue