summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorAndy Lester <andy@petdance.com>2020-03-25 04:26:44 (GMT)
committerGitHub <noreply@github.com>2020-03-25 04:26:44 (GMT)
commit7668a8bc93c2bd573716d1bea0f52ea520502b28 (patch)
tree0c6dce63a06466c3f9136df09f5cd928d20e5c55 /Modules
parent7dd549eb08939e1927fba818116f5202e76f8d73 (diff)
downloadcpython-7668a8bc93c2bd573716d1bea0f52ea520502b28.zip
cpython-7668a8bc93c2bd573716d1bea0f52ea520502b28.tar.gz
cpython-7668a8bc93c2bd573716d1bea0f52ea520502b28.tar.bz2
Use calloc-based functions, not malloc. (GH-19152)
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_ctypes/callproc.c6
-rw-r--r--Modules/_lzmamodule.c9
-rw-r--r--Modules/_winapi.c3
-rw-r--r--Modules/binascii.c10
-rw-r--r--Modules/faulthandler.c3
5 files changed, 9 insertions, 22 deletions
diff --git a/Modules/_ctypes/callproc.c b/Modules/_ctypes/callproc.c
index 5f29f95..d1c552a 100644
--- a/Modules/_ctypes/callproc.c
+++ b/Modules/_ctypes/callproc.c
@@ -156,10 +156,9 @@ _ctypes_get_errobj(int **pspace)
Py_INCREF(errobj);
}
else if (!PyErr_Occurred()) {
- void *space = PyMem_Malloc(sizeof(int) * 2);
+ void *space = PyMem_Calloc(2, sizeof(int));
if (space == NULL)
return NULL;
- memset(space, 0, sizeof(int) * 2);
errobj = PyCapsule_New(space, CTYPES_CAPSULE_NAME_PYMEM, pymem_destructor);
if (errobj == NULL) {
PyMem_Free(space);
@@ -1712,10 +1711,9 @@ resize(PyObject *self, PyObject *args)
if (!_CDataObject_HasExternalBuffer(obj)) {
/* We are currently using the objects default buffer, but it
isn't large enough any more. */
- void *ptr = PyMem_Malloc(size);
+ void *ptr = PyMem_Calloc(1, size);
if (ptr == NULL)
return PyErr_NoMemory();
- memset(ptr, 0, size);
memmove(ptr, obj->b_ptr, obj->b_size);
obj->b_ptr = ptr;
obj->b_size = size;
diff --git a/Modules/_lzmamodule.c b/Modules/_lzmamodule.c
index a2027be..714458b 100644
--- a/Modules/_lzmamodule.c
+++ b/Modules/_lzmamodule.c
@@ -212,10 +212,9 @@ parse_filter_spec_lzma(PyObject *spec)
return NULL;
}
- options = (lzma_options_lzma *)PyMem_Malloc(sizeof *options);
+ options = (lzma_options_lzma *)PyMem_Calloc(1, sizeof *options);
if (options == NULL)
return PyErr_NoMemory();
- memset(options, 0, sizeof *options);
if (lzma_lzma_preset(options, preset)) {
PyMem_Free(options);
@@ -257,10 +256,9 @@ parse_filter_spec_delta(PyObject *spec)
return NULL;
}
- options = (lzma_options_delta *)PyMem_Malloc(sizeof *options);
+ options = (lzma_options_delta *)PyMem_Calloc(1, sizeof *options);
if (options == NULL)
return PyErr_NoMemory();
- memset(options, 0, sizeof *options);
options->type = LZMA_DELTA_TYPE_BYTE;
options->dist = dist;
return options;
@@ -281,10 +279,9 @@ parse_filter_spec_bcj(PyObject *spec)
return NULL;
}
- options = (lzma_options_bcj *)PyMem_Malloc(sizeof *options);
+ options = (lzma_options_bcj *)PyMem_Calloc(1, sizeof *options);
if (options == NULL)
return PyErr_NoMemory();
- memset(options, 0, sizeof *options);
options->start_offset = start_offset;
return options;
}
diff --git a/Modules/_winapi.c b/Modules/_winapi.c
index 647075c..5dc50fb 100644
--- a/Modules/_winapi.c
+++ b/Modules/_winapi.c
@@ -603,11 +603,10 @@ _winapi_CreateJunction_impl(PyObject *module, LPWSTR src_path,
sizeof(rdb->MountPointReparseBuffer.PathBuffer) +
/* Two +1's for NUL terminators. */
(prefix_len + print_len + 1 + print_len + 1) * sizeof(WCHAR);
- rdb = (_Py_PREPARSE_DATA_BUFFER)PyMem_RawMalloc(rdb_size);
+ rdb = (_Py_PREPARSE_DATA_BUFFER)PyMem_RawCalloc(1, rdb_size);
if (rdb == NULL)
goto cleanup;
- memset(rdb, 0, rdb_size);
rdb->ReparseTag = IO_REPARSE_TAG_MOUNT_POINT;
rdb->ReparseDataLength = rdb_size - _Py_REPARSE_DATA_BUFFER_HEADER_SIZE;
rdb->MountPointReparseBuffer.SubstituteNameOffset = 0;
diff --git a/Modules/binascii.c b/Modules/binascii.c
index f59cb7d..1f3248b 100644
--- a/Modules/binascii.c
+++ b/Modules/binascii.c
@@ -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) {
diff --git a/Modules/faulthandler.c b/Modules/faulthandler.c
index ba88d98..ec9debc 100644
--- a/Modules/faulthandler.c
+++ b/Modules/faulthandler.c
@@ -911,10 +911,9 @@ faulthandler_register_py(PyObject *self,
return NULL;
if (user_signals == NULL) {
- user_signals = PyMem_Malloc(NSIG * sizeof(user_signal_t));
+ user_signals = PyMem_Calloc(NSIG, sizeof(user_signal_t));
if (user_signals == NULL)
return PyErr_NoMemory();
- memset(user_signals, 0, NSIG * sizeof(user_signal_t));
}
user = &user_signals[signum];