8000 Initialize the states array with calloc in _macosx.m · matplotlib/matplotlib@dbb80f4 · GitHub
[go: up one dir, main page]

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
< 8000 td data-grid-cell-id="diff-f8af2176752b51c29acf55ec5cc5d912f5459e19ed40559edcd78aaf7a6f6863-4492-4491-0" data-selected="false" role="gridcell" style="background-color:var(--diffBlob-deletionNum-bgColor, var(--diffBlob-deletion-bgColor-num));text-align:center" tabindex="-1" valign="top" class="focusable-grid-cell diff-line-number position-relative left-side">4492
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];
-
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)
0