Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minor Numa safety patches #712

Merged
merged 2 commits into from
Aug 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/colorquant1.c
Original file line number Diff line number Diff line change
Expand Up @@ -3110,7 +3110,8 @@ PIXCMAP *cmap;
makeRGBToIndexTables(level, &rtab, &gtab, &btab);

/* The octarray will give a ptr from the octcube to the colorarray */
ncubes = numaGetCount(na);
if ((ncubes = numaGetCount(na)) == 0)
return ERROR_PTR("no slots in pixel occupation histogram", __func__, NULL);
octarray = (l_int32 *)LEPT_CALLOC(ncubes, sizeof(l_int32));

/* The colorarray will hold the colors of the first pixel
Expand Down
1 change: 1 addition & 0 deletions src/graphics.c
Original file line number Diff line number Diff line change
Expand Up @@ -1152,6 +1152,7 @@ PTA *pta1, *pta2, *ptad;

/* Generate the plot points */
pta1 = ptaCreate(n);
maxw = maxh = 0;
for (i = 0; i < n; i++) {
numaGetFValue(na, i, &val);
if (orient == L_HORIZONTAL_LINE) {
Expand Down
6 changes: 4 additions & 2 deletions src/numabasic.c
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,8 @@ l_int32 *array;
if (!na)
return (l_int32 *)ERROR_PTR("na not defined", __func__, NULL);

n = numaGetCount(na);
if ((n = numaGetCount(na)) == 0)
return ERROR_PTR("array not made (na is empty)", __func__, NULL);
if ((array = (l_int32 *)LEPT_CALLOC(n, sizeof(l_int32))) == NULL)
return (l_int32 *)ERROR_PTR("array not made", __func__, NULL);
for (i = 0; i < n; i++) {
Expand Down Expand Up @@ -859,7 +860,8 @@ l_float32 *array;
if (copyflag == L_NOCOPY) {
array = na->array;
} else { /* copyflag == L_COPY */
n = numaGetCount(na);
if ((n = numaGetCount(na)) == 0)
return ERROR_PTR("array not made (na is empty)", __func__, NULL);
if ((array = (l_float32 *)LEPT_CALLOC(n, sizeof(l_float32))) == NULL)
return (l_float32 *)ERROR_PTR("array not made", __func__, NULL);
for (i = 0; i < n; i++)
Expand Down
1 change: 1 addition & 0 deletions src/numafunc2.c
Original file line number Diff line number Diff line change
Expand Up @@ -1613,6 +1613,7 @@ l_float32 startval, binsize, rankcount, total, sum, fract, val;
numaGetSum(na, &total);
rankcount = rank * total; /* count that corresponds to rank */
sum = 0.0;
val = 0.0;
for (i = 0; i < n; i++) {
numaGetFValue(na, i, &val);
if (sum + val >= rankcount)
Expand Down
Loading