#191 clang-tidy reduce NOLINTs using asserts, remove DeadStores

This commit is contained in:
gitlost 2020-07-19 10:31:12 +01:00
parent dd2bdb4335
commit 52d08fd9b9
12 changed files with 35 additions and 34 deletions

View File

@ -32,7 +32,6 @@
/* vim: set ts=4 sw=4 et : */ /* vim: set ts=4 sw=4 et : */
#include <stdio.h> #include <stdio.h>
#include <string.h>
#ifdef _MSC_VER #ifdef _MSC_VER
#include <malloc.h> #include <malloc.h>
#endif #endif
@ -1579,7 +1578,6 @@ INTERNAL int aztec_runes(struct zint_symbol *symbol, unsigned char source[], int
char binary_string[28]; char binary_string[28];
unsigned char data_codewords[3], ecc_codewords[6]; unsigned char data_codewords[3], ecc_codewords[6];
error_number = 0;
input_value = 0; input_value = 0;
if (length > 3) { if (length > 3) {
strcpy(symbol->errtxt, "507: Input too large"); strcpy(symbol->errtxt, "507: Input too large");

View File

@ -37,7 +37,7 @@
*/ */
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <assert.h>
#include <math.h> #include <math.h>
#ifndef _MSC_VER #ifndef _MSC_VER
#include <stdint.h> #include <stdint.h>
@ -322,7 +322,7 @@ static void rsencode(int nd, int nc, unsigned char *wd) {
wd[start + i * step] = 0; wd[start + i * step] = 0;
} }
for (i = 0; i < ND; i++) { 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++) { 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; 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) { static int n_digits(const unsigned char source[], int position, int length) {
int i; 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; 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 lawrencium[6]; // Reversed radix 103 values
int nx; int nx;
#if defined(_MSC_VER) && _MSC_VER == 1200
uint64_t binary_buffer = 0; uint64_t binary_buffer = 0;
#else
uint64_t binary_buffer = 0ULL;
#endif
input_position = 0; input_position = 0;
array_length = 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 */ /* The rest of the data uses 9-bit dot patterns from Annex C */
for (i = 1; i < array_length; i++) { 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); 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); 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); ecc_length = 3 + (data_length / 2);
if (debug & ZINT_DEBUG_PRINT) { if (debug & ZINT_DEBUG_PRINT) {

View File

@ -34,7 +34,7 @@
* and [MS-WMF] - v20160714, Released July 14, 2016 */ * and [MS-WMF] - v20160714, Released July 14, 2016 */
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <assert.h>
#include <math.h> #include <math.h>
#ifdef _MSC_VER #ifdef _MSC_VER
#include <malloc.h> #include <malloc.h>
@ -634,10 +634,13 @@ INTERNAL int emf_plot(struct zint_symbol *symbol) {
fwrite(&emr_selectobject_font, sizeof (emr_selectobject_t), 1, emf_file); 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++) { for (i = 0; i < string_count; i++) {
spacing = 8 * symbol->scale; spacing = 8 * symbol->scale;
fwrite(&text[i], sizeof (emr_exttextoutw_t), 1, emf_file); 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]); free(this_string[i]);
for (j = 0; j < bump_up(text[i].w_emr_text.chars + 1); j++) { for (j = 0; j < bump_up(text[i].w_emr_text.chars + 1); j++) {
fwrite(&spacing, 4, 1, emf_file); fwrite(&spacing, 4, 1, emf_file);

View File

@ -34,7 +34,6 @@
AIM Global Document Number AIMD014 Rev. 1.63 Revised 9 Dec 2008 */ AIM Global Document Number AIMD014 Rev. 1.63 Revised 9 Dec 2008 */
#include <stdio.h> #include <stdio.h>
#include <string.h>
#ifdef _MSC_VER #ifdef _MSC_VER
#include <malloc.h> #include <malloc.h>
#endif #endif
@ -277,7 +276,6 @@ static int gm_encode(unsigned int gbdata[], const size_t length, char binary[],
sp = 0; sp = 0;
current_mode = 0; current_mode = 0;
last_mode = 0;
number_pad_posn = 0; number_pad_posn = 0;
if (reader) { if (reader) {

View File

@ -674,7 +674,6 @@ INTERNAL int gs1_verify(struct zint_symbol *symbol, const unsigned char source[]
/* Resolve AI data - put resulting string in 'reduced' */ /* Resolve AI data - put resulting string in 'reduced' */
j = 0; j = 0;
last_ai = 0;
ai_latch = 1; ai_latch = 1;
for (i = 0; i < (int) src_len; i++) { for (i = 0; i < (int) src_len; i++) {
if ((source[i] != '[') && (source[i] != ']')) { if ((source[i] != '[') && (source[i] != ']')) {

View File

@ -35,7 +35,6 @@
#include "common.h" #include "common.h"
#include "maxicode.h" #include "maxicode.h"
#include "reedsol.h" #include "reedsol.h"
#include <string.h>
static int maxi_codeword[144]; 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) { if (set[i] == 2) {
character[i] = 51; character[i] = 51;
} }
done = 1; // done = 1 // As long as last branch not needed
} }
} }
} }

View File

@ -30,7 +30,6 @@
*/ */
/* vim: set ts=4 sw=4 et : */ /* vim: set ts=4 sw=4 et : */
#include <string.h>
#ifdef _MSC_VER #ifdef _MSC_VER
#include <malloc.h> #include <malloc.h>
#endif #endif
@ -692,6 +691,9 @@ static void add_ecc(unsigned char fullstream[], const unsigned char datastream[]
qty_short_blocks = blocks - qty_long_blocks; qty_short_blocks = blocks - qty_long_blocks;
ecc_block_length = ecc_cw / 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 #ifndef _MSC_VER
unsigned char data_block[short_data_block_length + 1]; 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) { 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];
interleaved_data[(short_data_block_length * blocks) + (i - qty_short_blocks)] = data_block[short_data_block_length]; // NOLINT
} }
for (j = 0; j < ecc_block_length; j++) { 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)); char* local = (char *) _alloca((size * size) * sizeof (char));
#endif #endif
/* Suppresses clang-tidy clang-analyzer-core.UndefinedBinaryOperatorResult warnings */
assert(size > 0);
#ifdef ZINTLOG #ifdef ZINTLOG
write_log(""); 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 */ /* Test 2: Block of modules in same color */
for (x = 0; x < size - 1; x++) { for (x = 0; x < size - 1; x++) {
for (y = 0; y < size - 1; y++) { 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]) &&
if (((local[(y * size) + x] == local[((y + 1) * size) + x]) && // NOLINT
(local[(y * size) + x] == local[(y * size) + (x + 1)])) && (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; result += 3;
} }
} }

View File

@ -33,17 +33,15 @@
#include <stdio.h> #include <stdio.h>
#ifdef _MSC_VER #ifdef _MSC_VER
#include <malloc.h>
#include <fcntl.h> #include <fcntl.h>
#include <io.h> #include <io.h>
#endif #endif
#include <math.h> #include <math.h>
#include <assert.h>
#include "common.h" #include "common.h"
#include "output.h" #include "output.h"
#ifdef _MSC_VER
#include <malloc.h>
#endif /* _MSC_VER */
#include "font.h" /* Font for human readable text */ #include "font.h" /* Font for human readable text */
#define SSET "0123456789ABCDEF" #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); string_left_hand = xposn - ((letter_width * string_length) / 2);
for (i = 0; i < string_length; i++) { 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); 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: case 0xC2:
/* UTF-8 C2xxh */ /* UTF-8 C2xxh */
/* Character range: C280h (latin: 80h) to C2BFh (latin: BFh) */ /* Character range: C280h (latin: 80h) to C2BFh (latin: BFh) */
assert(i + 1 < input_length);
i++; i++;
preprocessed[j] = source[i]; preprocessed[j] = source[i];
j++; j++;
@ -663,6 +663,7 @@ static void to_iso8859_1(const unsigned char source[], unsigned char preprocesse
case 0xC3: case 0xC3:
/* UTF-8 C3xx */ /* UTF-8 C3xx */
/* Character range: C380h (latin: C0h) to C3BFh (latin: FFh) */ /* Character range: C380h (latin: C0h) to C3BFh (latin: FFh) */
assert(i + 1 < input_length);
i++; i++;
preprocessed[j] = source[i] + 64; preprocessed[j] = source[i] + 64;
j++; j++;
@ -954,11 +955,7 @@ static int plot_raster_default(struct zint_symbol *symbol, int rotate_angle, int
} }
if (!textdone) { if (!textdone) {
#ifndef _MSC_VER unsigned char local_text[sizeof(symbol->text)];
unsigned char local_text[ustrlen(symbol->text) + 1];
#else
unsigned char* local_text = (unsigned char*) _alloca(ustrlen(symbol->text) + 1);
#endif
to_iso8859_1(symbol->text, local_text); to_iso8859_1(symbol->text, local_text);
/* Put the human readable text at the bottom */ /* Put the human readable text at the bottom */
textpos = 2 * (main_width / 2 + xoffset); textpos = 2 * (main_width / 2 + xoffset);

View File

@ -52,6 +52,7 @@
#ifdef _MSC_VER #ifdef _MSC_VER
#include <malloc.h> #include <malloc.h>
#endif #endif
#include <assert.h>
#include "common.h" #include "common.h"
#include "reedsol.h" #include "reedsol.h"
static int logmod; // 2**symsize - 1 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) { INTERNAL void rs_init_gf(const int poly) {
int m, b, p, v; 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 // Find the top bit, and hence the symbol size
for (b = 1, m = 0; b <= poly; b <<= 1) for (b = 1, m = 0; b <= poly; b <<= 1)
m++; m++;

View File

@ -1291,6 +1291,8 @@ INTERNAL int rssexpanded(struct zint_symbol *symbol, unsigned char source[], int
char* binary_string = (char*) _alloca(bin_len); char* binary_string = (char*) _alloca(bin_len);
#endif #endif
separator_row = 0;
i = gs1_verify(symbol, source, src_len, reduced); i = gs1_verify(symbol, source, src_len, reduced);
if (i != 0) { if (i != 0) {
return i; return i;

View File

@ -1,5 +1,5 @@
--- ../../../../postscriptbarcode/build/monolithic/barcode.ps 2020-07-14 14:52:24.208222925 +0100 --- ../../../../postscriptbarcode/build/monolithic/barcode.ps 2020-07-17 22:03:49.625837028 +0100
+++ ../tools/bwipp_dump.ps 2020-07-14 17:29:15.314238749 +0100 +++ ../tools/bwipp_dump.ps 2020-07-17 22:10:29.222780872 +0100
@@ -29,6 +29,8 @@ @@ -29,6 +29,8 @@
% CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS % CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
% IN THE SOFTWARE. % IN THE SOFTWARE.