1
0
mirror of https://git.code.sf.net/p/zint/code synced 2026-07-31 02:19:50 +00:00

general: suppress clang-tidy-21/22 warnings;

some code fiddling on affected files
manual: use new lua filter "lua-crossrefs.lua" hacked from
  https://github.com/rnwst/pandoc-lua-crossrefs as replacement for
  tablenos which broke with pandoc 2.8.2 (get nicer output anyway);
  fix "excode39.svg" data $ -> # to avoid shell processing;
  document `ZBarcode_HaveGS1SyntaxEngine()`
This commit is contained in:
gitlost
2025-10-08 12:21:29 +01:00
parent d413255c93
commit a3cca33f32
30 changed files with 1645 additions and 1080 deletions
+26 -20
View File
@@ -30,8 +30,8 @@
*/
/* SPDX-License-Identifier: BSD-3-Clause */
static const char GDSET[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz #";
#define GDSET_F (IS_NUM_F | IS_UPR_F | IS_LWR_F | IS_SPC_F | IS_HSH_F)
static const char AusGDSET[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz #";
#define AUS_GDSET_F (IS_NUM_F | IS_UPR_F | IS_LWR_F | IS_SPC_F | IS_HSH_F)
static const char AusNTable[10][2] = {
{'0','0'}, {'0','1'}, {'0','2'}, {'1','0'}, {'1','1'}, {'1','2'}, {'2','0'}, {'2','1'}, {'2','2'}, {'3','0'}
@@ -65,25 +65,27 @@ static const char AusBarTable[64][3] = {
{'3','3','0'}, {'3','3','1'}, {'3','3','2'}, {'3','3','3'}
};
#include <assert.h>
#include <stdio.h>
#include "common.h"
#include "reedsol.h"
static char aus_convert_pattern(char data, int shift) {
static unsigned char aus_convert_pattern(const char data, const int shift) {
return (data - '0') << shift;
}
/* Adds Reed-Solomon error correction to auspost */
static char *aus_rs_error(char data_pattern[], char *d) {
int reader, length, triple_writer = 0;
static char *aus_rs_error(const char data_pattern[], char *d) {
const int length = d - data_pattern;
int reader, triple_writer;
unsigned char triple[31];
unsigned char result[5];
rs_t rs;
for (reader = 2, length = d - data_pattern; reader < length; reader += 3, triple_writer++) {
for (reader = 2, triple_writer = 0; reader < length; reader += 3, triple_writer++) {
triple[triple_writer] = aus_convert_pattern(data_pattern[reader], 4)
+ aus_convert_pattern(data_pattern[reader + 1], 2)
+ aus_convert_pattern(data_pattern[reader + 2], 0);
| aus_convert_pattern(data_pattern[reader + 1], 2)
| aus_convert_pattern(data_pattern[reader + 2], 0);
}
zint_rs_init_gf(&rs, 0x43);
@@ -97,6 +99,7 @@ static char *aus_rs_error(char data_pattern[], char *d) {
return d;
}
/* In "postal.c" */
INTERNAL int zint_daft_set_height(struct zint_symbol *symbol, const float min_height, const float max_height);
/* Handles Australia Posts's 4 State Codes */
@@ -119,11 +122,14 @@ INTERNAL int zint_auspost(struct zint_symbol *symbol, unsigned char source[], in
char data_pattern[200];
char *d = data_pattern;
unsigned char fcc[2] = {0}; /* Suppress clang-tidy warning clang-analyzer-core.UndefinedBinaryOperatorResult */
unsigned char dpid[9];
unsigned char local_source[30];
int zeroes = 0;
const int raw_text = symbol->output_options & BARCODE_RAW_TEXT;
/* Suppress clang-tidy-21 clang-analyzer-security.ArrayBound */
assert(symbol->symbology == BARCODE_AUSPOST || symbol->symbology == BARCODE_AUSREPLY
|| symbol->symbology == BARCODE_AUSROUTE || symbol->symbology == BARCODE_AUSREDIRECT);
/* Do all of the length checking first to avoid stack smashing */
if (symbol->symbology == BARCODE_AUSPOST) {
if (length != 8 && length != 13 && length != 16 && length != 18 && length != 23) {
@@ -134,8 +140,8 @@ INTERNAL int zint_auspost(struct zint_symbol *symbol, unsigned char source[], in
return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 403, "Input length %d too long (maximum 8)", length);
}
/* Check input immediately to catch nuls */
if ((i = z_not_sane(GDSET_F, source, length))) {
/* Check input immediately to catch invalid chars */
if ((i = z_not_sane(AUS_GDSET_F, source, length))) {
return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 404,
"Invalid character at position %d in input (alphanumerics, space and \"#\" only)", i);
}
@@ -187,9 +193,9 @@ INTERNAL int zint_auspost(struct zint_symbol *symbol, unsigned char source[], in
memcpy(local_source + zeroes, source, length);
length += zeroes;
/* Verify that the first 8 characters are numbers */
memcpy(dpid, local_source, 8);
if ((i = z_not_sane(NEON_F, dpid, 8))) {
if ((i = z_not_sane(NEON_F, local_source, 8))) {
return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 405,
"Invalid character at position %d in DPID (first 8 characters) (digits only)", i);
}
@@ -205,16 +211,16 @@ INTERNAL int zint_auspost(struct zint_symbol *symbol, unsigned char source[], in
/* Delivery Point Identifier (DPID) */
for (reader = 0; reader < 8; reader++, d += 2) {
memcpy(d, AusNTable[dpid[reader] - '0'], 2);
memcpy(d, AusNTable[local_source[reader] - '0'], 2);
}
/* Customer Information */
if (length > 8) {
if ((length == 13) || (length == 18)) {
if (length == 13 || length == 18) {
for (reader = 8; reader < length; reader++, d += 3) {
memcpy(d, AusCTable[z_posn(GDSET, local_source[reader])], 3);
memcpy(d, AusCTable[z_posn(AusGDSET, local_source[reader])], 3);
}
} else if ((length == 16) || (length == 23)) {
} else if (length == 16 || length == 23) {
for (reader = 8; reader < length; reader++, d += 2) {
memcpy(d, AusNTable[local_source[reader] - '0'], 2);
}
@@ -244,11 +250,11 @@ INTERNAL int zint_auspost(struct zint_symbol *symbol, unsigned char source[], in
writer = 0;
h = d - data_pattern;
for (loopey = 0; loopey < h; loopey++) {
if ((data_pattern[loopey] == '1') || (data_pattern[loopey] == '0')) {
if (data_pattern[loopey] == '1' || data_pattern[loopey] == '0') {
z_set_module(symbol, 0, writer);
}
z_set_module(symbol, 1, writer);
if ((data_pattern[loopey] == '2') || (data_pattern[loopey] == '0')) {
if (data_pattern[loopey] == '2' || data_pattern[loopey] == '0') {
z_set_module(symbol, 2, writer);
}
writer += 2;
@@ -272,7 +278,7 @@ INTERNAL int zint_auspost(struct zint_symbol *symbol, unsigned char source[], in
symbol->row_height[1] = 2.0f;
error_number = zint_daft_set_height(symbol, 0.0f, 0.0f);
}
symbol->rows = 3;
symbol->rows = 3; /* Not stackable */
symbol->width = writer - 1;
if (raw_text && z_rt_cpy_cat(symbol, fcc, 2, '\xFF' /*separator (none)*/, local_source, length)) {
+6 -5
View File
@@ -204,7 +204,7 @@ static int c1_look_ahead_test(const unsigned char source[], const int length, co
for (sp = position; sp < length; sp++) {
const unsigned char c = source[sp];
const int is_extended = c & 0x80;
const int is_extended = !z_isascii(c);
/* Step L */
if (z_isdigit(c)) {
@@ -456,7 +456,7 @@ static int c1_c40text_cnt(const int current_mode, const int gs1, unsigned char i
return 2;
}
cnt = 1;
if (input & 0x80) {
if (!z_isascii(input)) {
cnt += 2;
input -= 128;
}
@@ -646,7 +646,7 @@ static int c1_encode(struct zint_symbol *symbol, unsigned char source[], int len
if (next_mode == C1_ASCII) {
if (debug_print) printf("ASC(%d) ", source[sp]);
if (source[sp] & 0x80) {
if (!z_isascii(source[sp])) {
/* Step B7 */
target[tp++] = 235; /* FNC4 (Upper Shift) */
target[tp++] = (source[sp] - 128) + 1;
@@ -700,9 +700,10 @@ static int c1_encode(struct zint_symbol *symbol, unsigned char source[], int len
}
if (debug_print) fputs(current_mode == C1_C40 ? "C40 " : "TEXT ", stdout);
if (source[sp] & 0x80) {
if (!z_isascii(source[sp])) {
cte_buffer[cte_p++] = 1; /* Shift 2 */
cte_buffer[cte_p++] = 30; /* FNC4 (Upper Shift) */
assert(source[sp] >= 128); /* Suppress clang-tidy-21 clang-analyzer-security.ArrayBound */
if (ct_shift[source[sp] - 128]) {
cte_buffer[cte_p++] = ct_shift[source[sp] - 128] - 1;
}
@@ -900,7 +901,7 @@ static int c1_encode(struct zint_symbol *symbol, unsigned char source[], int len
if (z_is_twodigits(source, length, sp)) {
target[tp++] = z_to_int(source + sp, 2) + 130;
sp++;
} else if (source[sp] & 0x80) {
} else if (!z_isascii(source[sp])) {
target[tp++] = 235; /* FNC4 (Upper Shift) */
target[tp++] = (source[sp] - 128) + 1;
} else if (gs1 && source[sp] == '\x1D') {
+2
View File
@@ -572,6 +572,8 @@ static void cc_c(struct zint_symbol *symbol, const char source[], const int cc_w
chainemc[mclength++] = mccorrection[i];
}
assert(cc_width > 0); /* Suppress clang-tidy-21 clang-analyzer-security.ArrayBound */
/* 818 - The CW string is finished */
symbol->rows = mclength / cc_width;
c1 = (symbol->rows - 1) / 3;
+8
View File
@@ -549,6 +549,7 @@ static int dm_edi_buffer_xfer(int process_buffer[8], int process_p, unsigned cha
memmove(process_buffer, process_buffer + process_e, sizeof(int) * process_p);
if (empty) {
if (process_p == 3) {
assert(i < 6); /* Suppress clang-tidy-21 clang-analyzer-security.ArrayBound */
target[tp++] = (unsigned char) (process_buffer[i] << 2 | (process_buffer[i + 1] & 0x30) >> 4);
target[tp++] = (unsigned char) ((process_buffer[i + 1] & 0x0F) << 4
| (process_buffer[i + 2] & 0x3C) >> 2);
@@ -558,6 +559,7 @@ static int dm_edi_buffer_xfer(int process_buffer[8], int process_p, unsigned cha
target[tp - 3], target[tp - 2], target[tp - 1]);
}
} else if (process_p == 2) {
assert(i < 7); /* Suppress clang-tidy-21 clang-analyzer-security.ArrayBound */
target[tp++] = (unsigned char) (process_buffer[i] << 2 | (process_buffer[i + 1] & 0x30) >> 4);
target[tp++] = (unsigned char) ((process_buffer[i + 1] & 0x0F) << 4);
if (debug_print) {
@@ -565,6 +567,7 @@ static int dm_edi_buffer_xfer(int process_buffer[8], int process_p, unsigned cha
target[tp - 1]);
}
} else {
assert(i < 8); /* Suppress clang-tidy-21 clang-analyzer-security.ArrayBound */
target[tp++] = (unsigned char) (process_buffer[i] << 2);
if (debug_print) printf("[%d (%d)] ", process_buffer[i], target[tp - 1]);
}
@@ -932,6 +935,8 @@ static void dm_addEdges(struct zint_symbol *symbol, const unsigned char source[]
const int last_seg, struct dm_edge *edges, const int from, struct dm_edge *previous, const int gs1) {
int i, pos;
assert(from < length); /* Suppress clang-tidy-21 clang-analyzer-security.ArrayBound */
/* Not possible to unlatch a full EDF edge to something else */
if (previous == NULL || previous->endMode != DM_EDIFACT) {
@@ -1880,6 +1885,8 @@ static int dm_ecc200(struct zint_symbol *symbol, struct zint_seg segs[], const i
datablock = dm_matrixdatablock[symbolsize];
rsblock = dm_matrixrsblock[symbolsize];
assert(H > 1 && W > 1); /* Suppress clang-tidy-21 clang-analyzer-security.ArrayBound */
taillength = bytes - binlen;
if (taillength != 0) {
@@ -1898,6 +1905,7 @@ static int dm_ecc200(struct zint_symbol *symbol, struct zint_seg segs[], const i
dm_ecc(binary, bytes, datablock, rsblock, skew);
if (debug_print) {
printf("ECC (%d): ", rsblock * (bytes / datablock));
assert(bytes > 0); /* Suppress clang-tidy-21 clang-analyzer-security.ArrayBound */
for (i = bytes; i < bytes + rsblock * (bytes / datablock); i++) printf("%d ", binary[i]);
fputc('\n', stdout);
}
+9 -1
View File
@@ -151,6 +151,10 @@ static int u_ascii_inv(const unsigned int u, unsigned char *dest) {
return 0;
}
/* `NOLINT`s required due to disconnect between `z_decode_utf8()` decoding lengths and `zint_get_eci_length()` */
/* NOLINTBEGIN(clang-analyzer-security.ArrayBound) clang-tidy-21 false positive */
/* ECI 25 UTF-16 Big Endian (ISO/IEC 10646) - assumes valid Unicode */
static int u_utf16be(const unsigned int u, unsigned char *dest) {
unsigned int u2, v;
@@ -205,6 +209,8 @@ static int u_utf32le(const unsigned int u, unsigned char *dest) {
return 4;
}
/* NOLINTEND(clang-analyzer-security.ArrayBound) */
/* ECI 899 Binary, included for libzueci compatibility - assumes valid Unicode */
static int u_binary(const unsigned int u, unsigned char *dest) {
if (u <= 0xFF) {
@@ -634,6 +640,7 @@ static int u_gb18030(const unsigned int u, unsigned char *dest) {
unsigned int d1, d2;
int ret = u_gb18030_int(u, &d1, &d2);
if (ret) {
/* NOLINTBEGIN(clang-analyzer-security.ArrayBound) clang-tidy-21 false positive */
if (ret == 1) {
dest[0] = (unsigned char) d1;
} else {
@@ -644,6 +651,7 @@ static int u_gb18030(const unsigned int u, unsigned char *dest) {
dest[3] = (unsigned char) d2;
}
}
/* NOLINTEND(clang-analyzer-security.ArrayBound) */
}
return ret;
}
@@ -794,7 +802,7 @@ INTERNAL int zint_utf8_to_eci(const int eci, const unsigned char source[], unsig
}
out_posn += incr;
}
dest[out_posn] = '\0';
dest[out_posn] = '\0'; /* NOLINT(clang-analyzer-security.ArrayBound) clang-tidy-21 false positive */
*p_length = out_posn;
return 0;
+29 -27
View File
@@ -33,6 +33,7 @@
/* This file implements Grid Matrix as specified in
AIM Global Document Number AIMD014 Rev. 1.63 Revised 9 Dec 2008 */
#include <assert.h>
#include <stdio.h>
#include "common.h"
#include "reedsol.h"
@@ -297,7 +298,7 @@ static void gm_add_byte_count(char binary[], const int byte_count_posn, const in
}
/* Add a control character to the data stream */
static int gm_add_shift_char(char binary[], int bp, int shifty, const int debug_print) {
static int gm_add_shift_char(char binary[], int bp, const int shifty, const int debug_print) {
int i;
int glyph = 0;
@@ -321,7 +322,7 @@ static int gm_add_shift_char(char binary[], int bp, int shifty, const int debug_
return bp;
}
static int gm_encode(unsigned int ddata[], const int length, char binary[], const int eci, int *p_bp,
static int gm_encode(const unsigned int ddata[], const int length, char binary[], const int eci, int *p_bp,
const int debug_print) {
/* Create a binary stream representation of the input data.
7 sets are defined - Chinese characters, Numerals, Lower case letters, Upper case letters,
@@ -733,10 +734,11 @@ static int gm_encode(unsigned int ddata[], const int length, char binary[], cons
return 0;
}
static int gm_encode_segs(unsigned int ddata[], const struct zint_seg segs[], const int seg_count, char binary[],
const int reader, const struct zint_structapp *p_structapp, int *p_bin_len, const int debug_print) {
static int gm_encode_segs(const unsigned int ddata[], const struct zint_seg segs[], const int seg_count,
char binary[], const int reader, const struct zint_structapp *p_structapp, int *p_bin_len,
const int debug_print) {
int i;
unsigned int *dd = ddata;
const unsigned int *dd = ddata;
int bp = 0;
int p;
@@ -863,11 +865,10 @@ static void gm_add_ecc(const char binary[], const int data_posn, const int layer
}
}
static void gm_place_macromodule(char grid[], int x, int y, int word1, int word2, int size) {
int i, j;
i = (x * 6) + 1;
j = (y * 6) + 1;
static void gm_place_macromodule(char grid[], const int x, const int y, const int word1, const int word2,
const int size) {
const int i = (x * 6) + 1;
const int j = (y * 6) + 1;
if (word2 & 0x40) {
grid[(j * size) + i + 2] = '1';
@@ -913,10 +914,10 @@ static void gm_place_macromodule(char grid[], int x, int y, int word1, int word2
}
}
static void gm_place_data_in_grid(unsigned char word[], char grid[], int modules, int size) {
int x, y, macromodule, offset;
static void gm_place_data_in_grid(const unsigned char word[], char grid[], const int modules, const int size) {
int x, y, macromodule;
const int offset = 13 - ((modules - 1) / 2);
offset = 13 - ((modules - 1) / 2);
for (y = 0; y < modules; y++) {
for (x = 0; x < modules; x++) {
macromodule = gm_macro_matrix[((y + offset) * 27) + (x + offset)];
@@ -926,8 +927,9 @@ static void gm_place_data_in_grid(unsigned char word[], char grid[], int modules
}
/* Place the layer ID into each macromodule */
static void gm_place_layer_id(char *grid, int size, int layers, int modules, int ecc_level) {
static void gm_place_layer_id(char *grid, const int size, const int layers, const int ecc_level) {
int i, j, layer, start, stop;
const int modules = 1 + (layers << 1);
int *layerid = (int *) z_alloca(sizeof(int) * (layers + 1));
int *id = (int *) z_alloca(sizeof(int) * (modules * modules));
@@ -947,8 +949,8 @@ static void gm_place_layer_id(char *grid, int size, int layers, int modules, int
}
/* Calculate which value goes in each macromodule */
start = modules / 2;
stop = modules / 2;
start = modules >> 1;
stop = modules >> 1;
for (layer = 0; layer <= layers; layer++) {
for (i = start; i <= stop; i++) {
id[(start * modules) + i] = layerid[layer];
@@ -1174,24 +1176,24 @@ INTERNAL int zint_gridmatrix(struct zint_symbol *symbol, struct zint_seg segs[],
memset(grid, '0', size_squared);
gm_place_data_in_grid(word, grid, modules, size);
gm_place_layer_id(grid, size, layers, modules, ecc_level);
gm_place_layer_id(grid, size, layers, ecc_level);
/* Add macromodule frames */
for (x = 0; x < modules; x++) {
int dark = 1 - (x & 1);
const int x_offset = x * 6;
int dark = !(x & 1);
for (y = 0; y < modules; y++) {
if (dark == 1) {
if (dark) {
const int y_offset = y * 6 * size;
for (i = 0; i < 5; i++) {
grid[((y * 6) * size) + (x * 6) + i] = '1';
grid[(((y * 6) + 5) * size) + (x * 6) + i] = '1';
grid[(((y * 6) + i) * size) + (x * 6)] = '1';
grid[(((y * 6) + i) * size) + (x * 6) + 5] = '1';
grid[y_offset + x_offset + i] = '1';
grid[y_offset + 5 * size + x_offset + i] = '1';
grid[y_offset + i * size + x_offset] = '1';
grid[y_offset + i * size + x_offset + 5] = '1';
}
grid[(((y * 6) + 5) * size) + (x * 6) + 5] = '1';
dark = 0;
} else {
dark = 1;
grid[y_offset + 5 * size + x_offset + 5] = '1';
}
dark = !dark;
}
}
+2
View File
@@ -1640,6 +1640,7 @@ static int gs1se_verify(struct zint_symbol *symbol, const unsigned char source[]
char msgBuf[120];
gs1_encoder_init_status_t status = GS1_ENCODERS_INIT_SUCCESS;
gs1_encoder_init_opts_t opts = {
/* NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange) suppress clang-tidy-21 warning OR-ing enums */
sizeof(gs1_encoder_init_opts_t), gs1_encoder_iNO_SYNDICT | gs1_encoder_iQUIET, &status, msgBuf, sizeof(msgBuf)
};
gs1_encoder *ctx;
@@ -1847,6 +1848,7 @@ INTERNAL int zint_gs1_verify(struct zint_symbol *symbol, const unsigned char sou
}
}
if (i != length) {
assert(length > 0); /* Suppress clang-tidy-21 clang-analyzer-security.ArrayBound */
local_source = local_source_buf;
/* Replace with control-char placeholders */
for (i = 0, j = 0; i < length; i++) {
+2
View File
@@ -1395,6 +1395,8 @@ static int pdf_enc(struct zint_symbol *symbol, struct zint_seg segs[], const int
if (debug_print) printf("\nSymbol size:\n%d columns x %d rows\n", cols, rows);
assert(cols > 0); /* Suppress clang-tidy-21 clang-analyzer-security.ArrayBound */
/* 818 - The CW string is finished */
c1 = (rows - 1) / 3;
c2 = ecc * 3 + (rows - 1) % 3;
+5 -2
View File
@@ -30,10 +30,11 @@
*/
/* SPDX-License-Identifier: BSD-3-Clause */
#include <assert.h>
#include <stdio.h>
#include "common.h"
#define SSET_F (IS_NUM_F | IS_UHX_F) /* SSET "0123456789ABCDEF" */
#define PLESS_SSET_F (IS_NUM_F | IS_UHX_F) /* SSET "0123456789ABCDEF" */
static const char PlessTable[16][8] = {
{'1','3','1','3','1','3','1','3'}, {'3','1','1','3','1','3','1','3'}, {'1','3','3','1','1','3','1','3'},
@@ -67,7 +68,7 @@ INTERNAL int zint_plessey(struct zint_symbol *symbol, unsigned char source[], in
if (length > 67) { /* 16 + 67 * 16 + 4 * 8 + 19 = 1139 */
return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 370, "Input length %d too long (maximum 67)", length);
}
if ((i = z_not_sane(SSET_F, source, length))) {
if ((i = z_not_sane(PLESS_SSET_F, source, length))) {
return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 371,
"Invalid character at position %d in input (digits and \"ABCDEF\" only)", i);
}
@@ -334,6 +335,8 @@ INTERNAL int zint_msi_plessey(struct zint_symbol *symbol, unsigned char source[]
int no_checktext = 0;
const int raw_text = symbol->output_options & BARCODE_RAW_TEXT;
assert(length > 0); /* Suppress clang-tidy-21 clang-analyzer-security.ArrayBound */
if (length > 92) { /* 3 (Start) + 92 * 12 + 3 * 12 + 4 (Stop) = 1147 */
return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 372, "Input length %d too long (maximum 92)", length);
}
+4 -1
View File
@@ -76,6 +76,8 @@ static void ps_convert(const unsigned char *string, unsigned char *ps_string) {
const unsigned char *s;
unsigned char *p = ps_string;
/* `NOLINT` required due to disconnect between `symbol->text` and vector `string`s which are always <= */
/* NOLINTBEGIN(clang-analyzer-security.ArrayBound) clang-tidy-21 false positive */
for (s = string; *s; s++) {
switch (*s) {
case '(':
@@ -95,10 +97,10 @@ static void ps_convert(const unsigned char *string, unsigned char *ps_string) {
*p++ = *s;
}
break;
}
}
*p = '\0';
/* NOLINTEND(clang-analyzer-security.ArrayBound) */
}
#ifdef ZINT_TEST /* Wrapper for direct testing */
@@ -344,6 +346,7 @@ INTERNAL int zint_ps_plot(struct zint_symbol *symbol) {
for (i = 0; i <= 8; i++) {
for (rect = symbol->vector->rectangles; rect; rect = rect->next) {
if ((i == 0 && rect->colour == -1) || rect->colour == i) {
assert(u_i < rect_cnt); /* Suppress clang-tidy-21 clang-analyzer-security.ArrayBound */
ultra_rects[u_i++] = rect;
}
}
+4
View File
@@ -1829,6 +1829,8 @@ INTERNAL int zint_qrcode(struct zint_symbol *symbol, struct zint_seg segs[], con
size = qr_sizes[version - 1];
size_squared = size * size;
assert(size >= 21); /* Suppress clang-tidy-21 clang-analyzer-security.ArrayBound */
grid = (unsigned char *) z_alloca(size_squared);
memset(grid, 0, size_squared);
@@ -2736,6 +2738,8 @@ INTERNAL int zint_rmqr(struct zint_symbol *symbol, struct zint_seg segs[], const
h_size = rmqr_width[version];
v_size = rmqr_height[version];
assert(h_size >= 27 && v_size >= 7); /* Suppress clang-tidy-21 clang-analyzer-security.ArrayBound */
grid = (unsigned char *) z_alloca(h_size * v_size);
memset(grid, 0, h_size * v_size);
+2
View File
@@ -998,6 +998,8 @@ static int plot_raster_default(struct zint_symbol *symbol, const int rotate_angl
main_width = symbol->width;
assert(symbol->rows >= 1); /* Suppress clang-tidy-21 clang-analyzer-security.ArrayBound */
if (z_is_composite(symbol->symbology)) {
while (!z_module_is_set(symbol, symbol->rows - 1, comp_xoffset)) {
comp_xoffset++;
+2
View File
@@ -288,6 +288,8 @@ INTERNAL int zint_dbar_omnstk_set_height(struct zint_symbol *symbol, const int f
const int second_row = first_row + 2; /* 2 row separator */
int i;
assert(first_row >= 0); /* Suppress clang-tidy-21 clang-analyzer-security.ArrayBound */
for (i = 0; i < symbol->rows; i++) {
if (i != first_row && i != second_row) {
fixed_height += symbol->row_height[i];
+3
View File
@@ -59,6 +59,8 @@ static void svg_pick_colour(const int colour, char colour_code[7]) {
/* Convert text to use HTML entity codes */
static void svg_make_html_friendly(const unsigned char *string, char *html_version) {
/* `NOLINT` required due to disconnect between `symbol->text` and vector `string`s which are always <= */
/* NOLINTBEGIN(clang-analyzer-security.ArrayBound) clang-tidy-21 false positive */
for (; *string; string++) {
switch (*string) {
case '>':
@@ -93,6 +95,7 @@ static void svg_make_html_friendly(const unsigned char *string, char *html_versi
}
*html_version = '\0';
/* NOLINTEND(clang-analyzer-security.ArrayBound) */
}
/* Helper to output floating point attribute */
+5 -2
View File
@@ -1437,6 +1437,9 @@ int testUtilDataPath(char *buffer, int buffer_size, const char *subdir, const ch
int i;
#endif
assert(buffer); /* Suppress clang-tidy-21 clang-analyzer-core.NonNullParamChecker */
/* Apparently `getenv()` & `getcwd()` "taint" stuff (external attack vectors) hence later NOLINTs */
if ((cmake_src_dir = getenv("CMAKE_CURRENT_SOURCE_DIR")) != NULL) {
len = (int) strlen(cmake_src_dir);
if (len <= 0 || len >= buffer_size) {
@@ -1500,7 +1503,7 @@ int testUtilDataPath(char *buffer, int buffer_size, const char *subdir, const ch
}
if (subdir_len) {
if (*subdir != '/' && buffer[len - 1] != '/') {
if (*subdir != '/' && buffer[len - 1] != '/') { /* NOLINT(clang-analyzer-security.ArrayBound) - see above */
if (len + 1 >= buffer_size) {
fprintf(stderr, "testUtilDataPath: subdir len (%d) + 1 >= buffer_size (%d)\n", len, buffer_size);
return 0;
@@ -1518,7 +1521,7 @@ int testUtilDataPath(char *buffer, int buffer_size, const char *subdir, const ch
}
if (filename_len) {
if (*filename != '/' && buffer[len - 1] != '/') {
if (*filename != '/' && buffer[len - 1] != '/') { /* NOLINT(clang-analyzer-security.ArrayBound) - see above */
if (len + 1 >= buffer_size) {
fprintf(stderr, "testUtilDataPath: filename len (%d) + 1 >= buffer_size (%d)\n", len, buffer_size);
return 0;
+1
View File
@@ -278,6 +278,7 @@ INTERNAL int zint_tif_pixel_plot(struct zint_symbol *symbol, const unsigned char
bytes_per_strip = rows_per_strip * ((symbol->bitmap_width + pixels_per_sample - 1) / pixels_per_sample)
* samples_per_pixel;
assert(bytes_per_strip >= 0); /* Suppress clang-tidy-21 clang-analyzer-security.ArrayBound */
strip_offset = (uint32_t *) z_alloca(sizeof(uint32_t) * strip_count);
strip_bytes = (uint32_t *) z_alloca(sizeof(uint32_t) * strip_count);
+4
View File
@@ -32,6 +32,7 @@
/* This version was developed using AIMD/TSC15032-43 v0.99c Edit 60, dated 4th Nov 2015 */
#include <assert.h>
#include <stdio.h>
#include "common.h"
@@ -637,6 +638,8 @@ static int ult_generate_codewords(struct zint_symbol *symbol, const unsigned cha
char *mode = (char *) z_alloca(length + 1);
int *cw_fragment = (int *) z_alloca(sizeof(int) * (length * 2 + 1));
assert(length > 0); /* Suppress clang-tidy-21 clang-analyzer-security.ArrayBound */
/* Check for 06 Macro Sequence and crop accordingly */
if (length >= 9
&& source[0] == '[' && source[1] == ')' && source[2] == '>' && source[3] == '\x1e'
@@ -694,6 +697,7 @@ static int ult_generate_codewords(struct zint_symbol *symbol, const unsigned cha
}
input_locn += ascii_encoded;
} else if (mode[input_locn] == 'c') {
assert(c43_encoded >= 0); /* Suppress clang-tidy-21 clang-analyzer-security.ArrayBound */
for (i = 0; i < c43_encoded; i++) {
mode[input_locn + i] = 'c';
}