summaryrefslogtreecommitdiffstats
path: root/Python
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 /Python
parent7dd549eb08939e1927fba818116f5202e76f8d73 (diff)
downloadcpython-7668a8bc93c2bd573716d1bea0f52ea520502b28.zip
cpython-7668a8bc93c2bd573716d1bea0f52ea520502b28.tar.gz
cpython-7668a8bc93c2bd573716d1bea0f52ea520502b28.tar.bz2
Use calloc-based functions, not malloc. (GH-19152)
Diffstat (limited to 'Python')
-rw-r--r--Python/compile.c12
-rw-r--r--Python/pystate.c3
-rw-r--r--Python/thread_pthread.h3
3 files changed, 6 insertions, 12 deletions
diff --git a/Python/compile.c b/Python/compile.c
index fa4313a..1175c8f 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -561,13 +561,12 @@ compiler_enter_scope(struct compiler *c, identifier name,
struct compiler_unit *u;
basicblock *block;
- u = (struct compiler_unit *)PyObject_Malloc(sizeof(
+ u = (struct compiler_unit *)PyObject_Calloc(1, sizeof(
struct compiler_unit));
if (!u) {
PyErr_NoMemory();
return 0;
}
- memset(u, 0, sizeof(struct compiler_unit));
u->u_scope_type = scope_type;
u->u_argcount = 0;
u->u_posonlyargcount = 0;
@@ -770,12 +769,11 @@ compiler_new_block(struct compiler *c)
struct compiler_unit *u;
u = c->u;
- b = (basicblock *)PyObject_Malloc(sizeof(basicblock));
+ b = (basicblock *)PyObject_Calloc(1, sizeof(basicblock));
if (b == NULL) {
PyErr_NoMemory();
return NULL;
}
- memset((void *)b, 0, sizeof(basicblock));
/* Extend the singly linked list of blocks with new block. */
b->b_list = u->u_blocks;
u->u_blocks = b;
@@ -812,15 +810,13 @@ compiler_next_instr(basicblock *b)
{
assert(b != NULL);
if (b->b_instr == NULL) {
- b->b_instr = (struct instr *)PyObject_Malloc(
- sizeof(struct instr) * DEFAULT_BLOCK_SIZE);
+ b->b_instr = (struct instr *)PyObject_Calloc(
+ DEFAULT_BLOCK_SIZE, sizeof(struct instr));
if (b->b_instr == NULL) {
PyErr_NoMemory();
return -1;
}
b->b_ialloc = DEFAULT_BLOCK_SIZE;
- memset((char *)b->b_instr, 0,
- sizeof(struct instr) * DEFAULT_BLOCK_SIZE);
}
else if (b->b_iused == b->b_ialloc) {
struct instr *tmp;
diff --git a/Python/pystate.c b/Python/pystate.c
index 8f0b6b8..bd2e44d 100644
--- a/Python/pystate.c
+++ b/Python/pystate.c
@@ -206,12 +206,11 @@ PyInterpreterState_New(void)
return NULL;
}
- PyInterpreterState *interp = PyMem_RawMalloc(sizeof(PyInterpreterState));
+ PyInterpreterState *interp = PyMem_RawCalloc(1, sizeof(PyInterpreterState));
if (interp == NULL) {
return NULL;
}
- memset(interp, 0, sizeof(*interp));
interp->id_refcount = -1;
_PyRuntimeState *runtime = &_PyRuntime;
diff --git a/Python/thread_pthread.h b/Python/thread_pthread.h
index ff4266c..40e2e11 100644
--- a/Python/thread_pthread.h
+++ b/Python/thread_pthread.h
@@ -547,9 +547,8 @@ PyThread_allocate_lock(void)
if (!initialized)
PyThread_init_thread();
- lock = (pthread_lock *) PyMem_RawMalloc(sizeof(pthread_lock));
+ lock = (pthread_lock *) PyMem_RawCalloc(1, sizeof(pthread_lock));
if (lock) {
- memset((void *)lock, '\0', sizeof(pthread_lock));
lock->locked = 0;
status = pthread_mutex_init(&lock->mut, NULL);