Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dbb80f4

Browse files
committed
Initialize the states array with calloc in _macosx.m
To silence a warning about garbage data from the clang static analyzer. Also check the calloc return value.
1 parent 03e60dc commit dbb80f4

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/_macosx.m

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4489,7 +4489,12 @@ -(void)save_figure:(id)sender
44894489
NSMenu* menu = [button menu];
44904490
NSArray* items = [menu itemArray];
44914491
unsigned int n = [items count];
4492-
int* states = malloc(n*sizeof(int));
4492+
int* states = calloc(n, sizeof(int));
4493+
if (!states)
4494+
{
4495+
PyErr_SetString(PyExc_RuntimeError, "calloc failed");
4496+
return NULL;
4497+
}
44934498
int i;
44944499
unsigned int m = 0;
44954500
NSEnumerator* enumerator = [items objectEnumerator];
@@ -4504,7 +4509,6 @@ -(void)save_figure:(id)sender
45044509
states[i] = 1;
45054510
m++;
45064511
}
4507-
else states[i] = 0;
45084512
}
45094513
int j = 0;
45104514
PyObject* list = PyList_New(m);

0 commit comments

Comments
 (0)