diff --git a/backend/aztec.c b/backend/aztec.c index f5e88bd2..246bc480 100644 --- a/backend/aztec.c +++ b/backend/aztec.c @@ -32,7 +32,6 @@ /* vim: set ts=4 sw=4 et : */ #include -#include #ifdef _MSC_VER #include #endif @@ -1579,7 +1578,6 @@ INTERNAL int aztec_runes(struct zint_symbol *symbol, unsigned char source[], int char binary_string[28]; unsigned char data_codewords[3], ecc_codewords[6]; - error_number = 0; input_value = 0; if (length > 3) { strcpy(symbol->errtxt, "507: Input too large"); diff --git a/backend/dotcode.c b/backend/dotcode.c index 78f39141..1a017071 100644 --- a/backend/dotcode.c +++ b/backend/dotcode.c @@ -37,7 +37,7 @@ */ #include -#include +#include #include #ifndef _MSC_VER #include @@ -322,7 +322,7 @@ static void rsencode(int nd, int nc, unsigned char *wd) { wd[start + i * step] = 0; } for (i = 0; i < ND; i++) { - k = (wd[start + i * step] + wd[start + ND * step]) % GF; // NOLINT wd set 0..(nd - 1) and start + i * step <= nd - 1 + k = (wd[start + i * step] + wd[start + ND * step]) % GF; for (j = 0; j < NC - 1; j++) { wd[start + (ND + j) * step] = (GF - ((c[j + 1] * k) % GF) + wd[start + (ND + j + 1) * step]) % GF; } @@ -391,7 +391,7 @@ static int datum_c(const unsigned char source[], int position, int length) { static int n_digits(const unsigned char source[], int position, int length) { int i; - for (i = position; ((source[i] >= '0') && (source[i] <= '9')) && (i < length); i++); + for (i = position; (i < length) && ((source[i] >= '0') && (source[i] <= '9')); i++); return i - position; } @@ -490,11 +490,7 @@ static int dotcode_encode_message(struct zint_symbol *symbol, const unsigned cha int lawrencium[6]; // Reversed radix 103 values int nx; -#if defined(_MSC_VER) && _MSC_VER == 1200 uint64_t binary_buffer = 0; -#else - uint64_t binary_buffer = 0ULL; -#endif input_position = 0; array_length = 0; @@ -1130,7 +1126,7 @@ static size_t make_dotstream(unsigned char masked_array[], int array_length, cha /* The rest of the data uses 9-bit dot patterns from Annex C */ for (i = 1; i < array_length; i++) { - bin_append(dot_patterns[masked_array[i]], 9, dot_stream); // NOLINT masked_array values modulo 113 and fully set + bin_append(dot_patterns[masked_array[i]], 9, dot_stream); } return strlen(dot_stream); @@ -1335,6 +1331,9 @@ INTERNAL int dotcode(struct zint_symbol *symbol, const unsigned char source[], i data_length = dotcode_encode_message(symbol, source, length, codeword_array, &binary_finish); + /* Suppresses clang-tidy clang-analyzer-core.UndefinedBinaryOperatorResult/uninitialized.ArraySubscript warnings */ + assert(data_length > 0); + ecc_length = 3 + (data_length / 2); if (debug & ZINT_DEBUG_PRINT) { diff --git a/backend/emf.c b/backend/emf.c index bd6f6a29..d1e6e07f 100644 --- a/backend/emf.c +++ b/backend/emf.c @@ -34,7 +34,7 @@ * and [MS-WMF] - v20160714, Released July 14, 2016 */ #include -#include +#include #include #ifdef _MSC_VER #include @@ -634,10 +634,13 @@ INTERNAL int emf_plot(struct zint_symbol *symbol) { fwrite(&emr_selectobject_font, sizeof (emr_selectobject_t), 1, emf_file); } + /* Suppresses clang-tidy clang-analyzer-core.UndefinedBinaryOperatorResult warning */ + assert((symbol->vector->strings == NULL && string_count == 0) || (symbol->vector->strings != NULL && string_count > 0)); + for (i = 0; i < string_count; i++) { spacing = 8 * symbol->scale; fwrite(&text[i], sizeof (emr_exttextoutw_t), 1, emf_file); - fwrite(this_string[i], bump_up(text[i].w_emr_text.chars + 1) * 2, 1, emf_file); // NOLINT text set 0..(string_count - 1) + fwrite(this_string[i], bump_up(text[i].w_emr_text.chars + 1) * 2, 1, emf_file); free(this_string[i]); for (j = 0; j < bump_up(text[i].w_emr_text.chars + 1); j++) { fwrite(&spacing, 4, 1, emf_file); diff --git a/backend/gridmtx.c b/backend/gridmtx.c index 627057d3..a7642856 100644 --- a/backend/gridmtx.c +++ b/backend/gridmtx.c @@ -34,7 +34,6 @@ AIM Global Document Number AIMD014 Rev. 1.63 Revised 9 Dec 2008 */ #include -#include #ifdef _MSC_VER #include #endif @@ -277,7 +276,6 @@ static int gm_encode(unsigned int gbdata[], const size_t length, char binary[], sp = 0; current_mode = 0; - last_mode = 0; number_pad_posn = 0; if (reader) { diff --git a/backend/gs1.c b/backend/gs1.c index 2bee8631..4c8e5f82 100644 --- a/backend/gs1.c +++ b/backend/gs1.c @@ -674,7 +674,6 @@ INTERNAL int gs1_verify(struct zint_symbol *symbol, const unsigned char source[] /* Resolve AI data - put resulting string in 'reduced' */ j = 0; - last_ai = 0; ai_latch = 1; for (i = 0; i < (int) src_len; i++) { if ((source[i] != '[') && (source[i] != ']')) { diff --git a/backend/maxicode.c b/backend/maxicode.c index cf7200fe..8773c57f 100644 --- a/backend/maxicode.c +++ b/backend/maxicode.c @@ -35,7 +35,6 @@ #include "common.h" #include "maxicode.h" #include "reedsol.h" -#include static int maxi_codeword[144]; @@ -270,7 +269,7 @@ static int maxi_text_process(int mode, unsigned char source[], int length, int e if (set[i] == 2) { character[i] = 51; } - done = 1; + // done = 1 // As long as last branch not needed } } } diff --git a/backend/qr.c b/backend/qr.c index 40a1c324..0346d33c 100644 --- a/backend/qr.c +++ b/backend/qr.c @@ -30,7 +30,6 @@ */ /* vim: set ts=4 sw=4 et : */ -#include #ifdef _MSC_VER #include #endif @@ -692,6 +691,9 @@ static void add_ecc(unsigned char fullstream[], const unsigned char datastream[] qty_short_blocks = blocks - qty_long_blocks; ecc_block_length = ecc_cw / blocks; + /* Suppress some clang-tidy clang-analyzer-core.UndefinedBinaryOperatorResult/uninitialized.Assign warnings */ + assert(short_data_block_length >= 0); + assert(ecc_block_length * blocks == ecc_cw); #ifndef _MSC_VER unsigned char data_block[short_data_block_length + 1]; @@ -747,8 +749,7 @@ static void add_ecc(unsigned char fullstream[], const unsigned char datastream[] } if (i >= qty_short_blocks) { - /* NOLINT suppress clang-tidy warning: data_block[short_data_block_length] set for i >= qty_short_blocks */ - interleaved_data[(short_data_block_length * blocks) + (i - qty_short_blocks)] = data_block[short_data_block_length]; // NOLINT + interleaved_data[(short_data_block_length * blocks) + (i - qty_short_blocks)] = data_block[short_data_block_length]; } for (j = 0; j < ecc_block_length; j++) { @@ -988,6 +989,8 @@ static int evaluate(unsigned char *eval,const int size,const int pattern) { char* local = (char *) _alloca((size * size) * sizeof (char)); #endif + /* Suppresses clang-tidy clang-analyzer-core.UndefinedBinaryOperatorResult warnings */ + assert(size > 0); #ifdef ZINTLOG write_log(""); @@ -1072,10 +1075,9 @@ static int evaluate(unsigned char *eval,const int size,const int pattern) { /* Test 2: Block of modules in same color */ for (x = 0; x < size - 1; x++) { for (y = 0; y < size - 1; y++) { - /* NOLINT suppress clang-tidy warning: local[size * size] fully set */ - if (((local[(y * size) + x] == local[((y + 1) * size) + x]) && // NOLINT + if (((local[(y * size) + x] == local[((y + 1) * size) + x]) && (local[(y * size) + x] == local[(y * size) + (x + 1)])) && - (local[(y * size) + x] == local[((y + 1) * size) + (x + 1)])) { // NOLINT + (local[(y * size) + x] == local[((y + 1) * size) + (x + 1)])) { result += 3; } } diff --git a/backend/raster.c b/backend/raster.c index 569783d3..d0d8da98 100644 --- a/backend/raster.c +++ b/backend/raster.c @@ -33,17 +33,15 @@ #include #ifdef _MSC_VER +#include #include #include #endif #include +#include #include "common.h" #include "output.h" -#ifdef _MSC_VER -#include -#endif /* _MSC_VER */ - #include "font.h" /* Font for human readable text */ #define SSET "0123456789ABCDEF" @@ -436,6 +434,7 @@ static void draw_string(char *pixbuf, unsigned char input_string[], int xposn, i string_left_hand = xposn - ((letter_width * string_length) / 2); for (i = 0; i < string_length; i++) { + // NOLINTNEXTLINE(clang-analyzer-core.CallAndMessage) suppress (probable) false positive about 2nd arg input_string[i] being uninitialized draw_letter(pixbuf, input_string[i], string_left_hand + (i * letter_width), yposn, textflags, image_width, image_height); } } @@ -656,6 +655,7 @@ static void to_iso8859_1(const unsigned char source[], unsigned char preprocesse case 0xC2: /* UTF-8 C2xxh */ /* Character range: C280h (latin: 80h) to C2BFh (latin: BFh) */ + assert(i + 1 < input_length); i++; preprocessed[j] = source[i]; j++; @@ -663,6 +663,7 @@ static void to_iso8859_1(const unsigned char source[], unsigned char preprocesse case 0xC3: /* UTF-8 C3xx */ /* Character range: C380h (latin: C0h) to C3BFh (latin: FFh) */ + assert(i + 1 < input_length); i++; preprocessed[j] = source[i] + 64; j++; @@ -954,11 +955,7 @@ static int plot_raster_default(struct zint_symbol *symbol, int rotate_angle, int } if (!textdone) { -#ifndef _MSC_VER - unsigned char local_text[ustrlen(symbol->text) + 1]; -#else - unsigned char* local_text = (unsigned char*) _alloca(ustrlen(symbol->text) + 1); -#endif + unsigned char local_text[sizeof(symbol->text)]; to_iso8859_1(symbol->text, local_text); /* Put the human readable text at the bottom */ textpos = 2 * (main_width / 2 + xoffset); diff --git a/backend/reedsol.c b/backend/reedsol.c index 6d908e48..67e6b89f 100644 --- a/backend/reedsol.c +++ b/backend/reedsol.c @@ -52,6 +52,7 @@ #ifdef _MSC_VER #include #endif +#include #include "common.h" #include "reedsol.h" static int logmod; // 2**symsize - 1 @@ -72,6 +73,9 @@ static int *logt = NULL, *alog = NULL, *rspoly = NULL; INTERNAL void rs_init_gf(const int poly) { int m, b, p, v; + // Suppress clang-tidy clang-analyzer-core.UndefinedBinaryOperatorResult warning + assert(poly >= 2); + // Find the top bit, and hence the symbol size for (b = 1, m = 0; b <= poly; b <<= 1) m++; diff --git a/backend/rss.c b/backend/rss.c index 7bcdfec2..543ba176 100644 --- a/backend/rss.c +++ b/backend/rss.c @@ -1291,6 +1291,8 @@ INTERNAL int rssexpanded(struct zint_symbol *symbol, unsigned char source[], int char* binary_string = (char*) _alloca(bin_len); #endif + separator_row = 0; + i = gs1_verify(symbol, source, src_len, reduced); if (i != 0) { return i; diff --git a/backend/tests/tools/bwipp_dump-barcode.ps.diff b/backend/tests/tools/bwipp_dump-barcode.ps.diff index 7baa0503..9861d6b6 100644 --- a/backend/tests/tools/bwipp_dump-barcode.ps.diff +++ b/backend/tests/tools/bwipp_dump-barcode.ps.diff @@ -1,5 +1,5 @@ ---- ../../../../postscriptbarcode/build/monolithic/barcode.ps 2020-07-14 14:52:24.208222925 +0100 -+++ ../tools/bwipp_dump.ps 2020-07-14 17:29:15.314238749 +0100 +--- ../../../../postscriptbarcode/build/monolithic/barcode.ps 2020-07-17 22:03:49.625837028 +0100 ++++ ../tools/bwipp_dump.ps 2020-07-17 22:10:29.222780872 +0100 @@ -29,6 +29,8 @@ % CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS % IN THE SOFTWARE. diff --git a/backend/tests/tools/bwipp_dump.ps.tar.xz b/backend/tests/tools/bwipp_dump.ps.tar.xz index 53f5f9fb..48d222cb 100644 Binary files a/backend/tests/tools/bwipp_dump.ps.tar.xz and b/backend/tests/tools/bwipp_dump.ps.tar.xz differ