Skip to content

Commit

Permalink
Merge pull request #712 from GerHobbelt/numa-patch-2
Browse files Browse the repository at this point in the history
minor Numa safety patches
  • Loading branch information
DanBloomberg committed Aug 26, 2023
2 parents 5913624 + 9d7ecbe commit d819f01
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
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

0 comments on commit d819f01

Please sign in to comment.