From 66da9e99ce38e93673d4870c2c76f54bf653deb0 Mon Sep 17 00:00:00 2001 From: Alexandre Perrin Date: Mon, 3 Oct 2016 15:45:37 +0200 Subject: [PATCH] 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. --- lib/identify.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/identify.c b/lib/identify.c index 9ae9ee5..180e6b3 100644 --- a/lib/identify.c +++ b/lib/identify.c @@ -201,17 +201,19 @@ static void threshold(struct quirc *q) u = x; } - avg_w = (avg_w * (threshold_s - 1)) / - threshold_s + row[w]; - avg_u = (avg_u * (threshold_s - 1)) / - threshold_s + row[u]; + if (threshold_s > 0) { + avg_w = (avg_w * (threshold_s - 1)) / + threshold_s + row[w]; + avg_u = (avg_u * (threshold_s - 1)) / + threshold_s + row[u]; + } row_average[w] += avg_w; row_average[u] += avg_u; } 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)) row[x] = QUIRC_PIXEL_BLACK; else