Use calloc-based functions, not malloc. (GH-19152)

This commit is contained in:
Andy Lester 2020-03-24 23:26:44 -05:00 committed by GitHub
parent 7dd549eb08
commit 7668a8bc93
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 17 additions and 38 deletions

View file

@ -1311,15 +1311,12 @@ binascii_a2b_qp_impl(PyObject *module, Py_buffer *data, int header)
datalen = data->len;
/* We allocate the output same size as input, this is overkill.
* The previous implementation used calloc() so we'll zero out the
* memory here too, since PyMem_Malloc() does not guarantee that.
*/
odata = (unsigned char *) PyMem_Malloc(datalen);
odata = (unsigned char *) PyMem_Calloc(1, datalen);
if (odata == NULL) {
PyErr_NoMemory();
return NULL;
}
memset(odata, 0, datalen);
in = out = 0;
while (in < datalen) {
@ -1499,15 +1496,12 @@ binascii_b2a_qp_impl(PyObject *module, Py_buffer *data, int quotetabs,
}
/* We allocate the output same size as input, this is overkill.
* The previous implementation used calloc() so we'll zero out the
* memory here too, since PyMem_Malloc() does not guarantee that.
*/
odata = (unsigned char *) PyMem_Malloc(odatalen);
odata = (unsigned char *) PyMem_Calloc(1, odatalen);
if (odata == NULL) {
PyErr_NoMemory();
return NULL;
}
memset(odata, 0, odatalen);
in = out = linelen = 0;
while (in < datalen) {