Update version quirc
authorNesterov Alexander <nesoldr@mail.ru>
Wed, 20 May 2020 14:30:13 +0000 (17:30 +0300)
committerNesterov Alexander <nesoldr@mail.ru>
Wed, 20 May 2020 14:55:14 +0000 (17:55 +0300)
3rdparty/quirc/include/quirc_internal.h
3rdparty/quirc/src/decode.c
3rdparty/quirc/src/quirc.c
3rdparty/quirc/src/version_db.c

index 56f5d28..21cd561 100644 (file)
 #define QUIRC_PERSPECTIVE_PARAMS       8
 
 #if QUIRC_MAX_REGIONS < UINT8_MAX
+#define QUIRC_PIXEL_ALIAS_IMAGE        1
 typedef uint8_t quirc_pixel_t;
 #elif QUIRC_MAX_REGIONS < UINT16_MAX
+#define QUIRC_PIXEL_ALIAS_IMAGE        0
 typedef uint16_t quirc_pixel_t;
 #else
 #error "QUIRC_MAX_REGIONS > 65534 is not supported"
@@ -77,7 +79,6 @@ struct quirc_grid {
 struct quirc {
        uint8_t                 *image;
        quirc_pixel_t           *pixels;
-       int                     *row_average; /* used by threshold() */
        int                     w;
        int                     h;
 
index f556097..894b506 100644 (file)
@@ -874,7 +874,7 @@ static quirc_decode_error_t decode_payload(struct quirc_data *data,
 done:
 
        /* Add nul terminator to all payloads */
-       if ((unsigned)data->payload_len >= sizeof(data->payload))
+       if (data->payload_len >= (int) sizeof(data->payload))
                data->payload_len--;
        data->payload[data->payload_len] = 0;
 
index a1418b2..0cf5009 100644 (file)
@@ -39,9 +39,8 @@ void quirc_destroy(struct quirc *q)
        free(q->image);
        /* q->pixels may alias q->image when their type representation is of the
           same size, so we need to be careful here to avoid a double free */
-       if (sizeof(*q->image) != sizeof(*q->pixels))
+       if (!QUIRC_PIXEL_ALIAS_IMAGE)
                free(q->pixels);
-       free(q->row_average);
        free(q);
 }
 
@@ -49,7 +48,6 @@ int quirc_resize(struct quirc *q, int w, int h)
 {
        uint8_t         *image  = NULL;
        quirc_pixel_t   *pixels = NULL;
-       int             *row_average = NULL;
 
        /*
         * XXX: w and h should be size_t (or at least unsigned) as negatives
@@ -82,35 +80,27 @@ int quirc_resize(struct quirc *q, int w, int h)
        (void)memcpy(image, q->image, min);
 
        /* alloc a new buffer for q->pixels if needed */
-       if (sizeof(*q->image) != sizeof(*q->pixels)) {
+       if (!QUIRC_PIXEL_ALIAS_IMAGE) {
                pixels = calloc(newdim, sizeof(quirc_pixel_t));
                if (!pixels)
                        goto fail;
        }
 
-       /* alloc a new buffer for q->row_average */
-       row_average = calloc(w, sizeof(int));
-       if (!row_average)
-               goto fail;
-
        /* alloc succeeded, update `q` with the new size and buffers */
        q->w = w;
        q->h = h;
        free(q->image);
        q->image = image;
-       if (sizeof(*q->image) != sizeof(*q->pixels)) {
+       if (!QUIRC_PIXEL_ALIAS_IMAGE) {
                free(q->pixels);
                q->pixels = pixels;
        }
-       free(q->row_average);
-       q->row_average = row_average;
 
        return 0;
        /* NOTREACHED */
 fail:
        free(image);
        free(pixels);
-       free(row_average);
 
        return -1;
 }
@@ -133,6 +123,8 @@ static const char *const error_table[] = {
 
 const char *quirc_strerror(quirc_decode_error_t err)
 {
-       if ((int)err < 8) { return error_table[err]; }
-       else { return "Unknown error"; }
+       if ((int)err >= 0 && (int)err < sizeof(error_table) / sizeof(error_table[0]))
+               return error_table[err];
+
+       return "Unknown error";
 }
index 9c77e63..4242aee 100644 (file)
 #include <quirc_internal.h>
 
 const struct quirc_version_info quirc_version_db[QUIRC_MAX_VERSION + 1] = {
-                       { /* 0 */
-                               .data_bytes = 0,
-                               .apat = {0},
-                               .ecc = {
-                                       {.bs = 0, .dw = 0, .ns = 0},
-                                       {.bs = 0, .dw = 0, .ns = 0},
-                                       {.bs = 0, .dw = 0, .ns = 0},
-                                       {.bs = 0, .dw = 0, .ns = 0}
-                               }
-                       },
+           {0},
            { /* Version 1 */
                    .data_bytes = 26,
                    .apat = {0},