Avoid division by zero.
Before this patch, small images (i.e. 7x7 pixels or less) could trigger SIGFPE because of a (integer) division by zero.
This commit is contained in:
parent
87e79e769b
commit
66da9e99ce
1 changed files with 7 additions and 5 deletions
|
@ -201,17 +201,19 @@ static void threshold(struct quirc *q)
|
||||||
u = x;
|
u = x;
|
||||||
}
|
}
|
||||||
|
|
||||||
avg_w = (avg_w * (threshold_s - 1)) /
|
if (threshold_s > 0) {
|
||||||
threshold_s + row[w];
|
avg_w = (avg_w * (threshold_s - 1)) /
|
||||||
avg_u = (avg_u * (threshold_s - 1)) /
|
threshold_s + row[w];
|
||||||
threshold_s + row[u];
|
avg_u = (avg_u * (threshold_s - 1)) /
|
||||||
|
threshold_s + row[u];
|
||||||
|
}
|
||||||
|
|
||||||
row_average[w] += avg_w;
|
row_average[w] += avg_w;
|
||||||
row_average[u] += avg_u;
|
row_average[u] += avg_u;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (x = 0; x < q->w; x++) {
|
for (x = 0; x < q->w; x++) {
|
||||||
if (row[x] < row_average[x] *
|
if (threshold_s > 0 && row[x] < row_average[x] *
|
||||||
(100 - THRESHOLD_T) / (200 * threshold_s))
|
(100 - THRESHOLD_T) / (200 * threshold_s))
|
||||||
row[x] = QUIRC_PIXEL_BLACK;
|
row[x] = QUIRC_PIXEL_BLACK;
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in a new issue