diff --git a/backend/aztec.c b/backend/aztec.c
index ef011038..520c8163 100644
--- a/backend/aztec.c
+++ b/backend/aztec.c
@@ -46,53 +46,44 @@
#define AZ_BIN_CAP_CWDS_S "1661" /* String version of (AZTEC_BIN_CAPACITY / 12) */
/* Count number of consecutive (. SP) or (, SP) Punct mode doubles for comparison against Digit mode encoding */
-static int az_count_doubles(const unsigned char source[], int i, const int length) {
- int c = 0;
+static int az_count_doubles(const unsigned char source[], const int position, const int length) {
+ int i;
- while ((i + 1 < length) && ((source[i] == '.') || (source[i] == ',')) && (source[i + 1] == ' ')) {
- c++;
- i += 2;
- }
+ for (i = position; i + 1 < length && (source[i] == '.' || source[i] == ',') && source[i + 1] == ' '; i += 2);
- return c;
+ return (i - position) >> 1;
}
/* Count number of consecutive full stops or commas (can be encoded in Punct or Digit mode) */
-static int az_count_dotcomma(const unsigned char source[], int i, const int length) {
- int c = 0;
+static int az_count_dotcomma(const unsigned char source[], const int position, const int length) {
+ int i;
- while (i < length && ((source[i] == '.') || (source[i] == ','))) {
- c++;
- i++;
- }
+ for (i = position; i < length && (source[i] == '.' || source[i] == ','); i++);
- return c;
+ return i - position;
}
/* Count number of consecutive `chr`s */
-static int az_count_chr(const unsigned char source[], int i, const int length, const unsigned char chr) {
- int c = 0;
+static int az_count_chr(const unsigned char source[], const int position, const int length, const unsigned char chr) {
+ int i;
- while (i < length && source[i] == chr) {
- c++;
- i++;
- }
+ for (i = position; i < length && source[i] == chr; i++);
- return c;
+ return i - position;
}
/* Return mode following current, or 'E' if none */
-static char az_get_next_mode(const char encode_mode[], const int src_len, int i) {
- int current_mode = encode_mode[i];
+static char az_get_next_mode(const char encode_mode[], const int length, int i) {
+ const char current_mode = encode_mode[i];
do {
i++;
- } while ((i < src_len) && (encode_mode[i] == current_mode));
- if (i >= src_len) {
+ } while (i < length && encode_mode[i] == current_mode);
+
+ if (i >= length) {
return 'E';
- } else {
- return encode_mode[i];
}
+ return encode_mode[i];
}
/* Same as `z_bin_append_posn()`, except check for buffer overflow first */
@@ -105,7 +96,7 @@ static int az_bin_append_posn(const int arg, const int length, char *binary, con
}
/* Determine encoding modes and encode */
-static int aztec_text_process(const unsigned char source[], int src_len, int bp, char binary_string[], const int gs1,
+static int aztec_text_process(const unsigned char source[], int length, int bp, char binary_string[], const int gs1,
const int gs1_bp, const int eci, char *p_current_mode, int *data_length, const int debug_print) {
int i, j;
@@ -114,11 +105,11 @@ static int aztec_text_process(const unsigned char source[], int src_len, int bp,
int count;
char next_mode;
int reduced_length;
- char *encode_mode = (char *) z_alloca(src_len + 1);
- unsigned char *reduced_source = (unsigned char *) z_alloca(src_len + 1);
- char *reduced_encode_mode = (char *) z_alloca(src_len + 1);
+ char *encode_mode = (char *) z_alloca(length + 1);
+ unsigned char *reduced_source = (unsigned char *) z_alloca(length + 1);
+ char *reduced_encode_mode = (char *) z_alloca(length + 1);
- for (i = 0; i < src_len; i++) {
+ for (i = 0; i < length; i++) {
if (source[i] >= 128) {
encode_mode[i] = 'B';
} else if (gs1 && source[i] == '\x1D') {
@@ -131,41 +122,41 @@ static int aztec_text_process(const unsigned char source[], int src_len, int bp,
/* Deal first with letter combinations which can be combined to one codeword
Combinations are (CR LF) (. SP) (, SP) (: SP) in Punct mode */
current_mode = initial_mode;
- for (i = 0; i + 1 < src_len; i++) {
+ for (i = 0; i + 1 < length; i++) {
/* Combination (CR LF) should always be in Punct mode */
- if ((source[i] == 13) && (source[i + 1] == 10)) {
+ if (source[i] == 13 && source[i + 1] == 10) {
encode_mode[i] = 'P';
encode_mode[i + 1] = 'P';
/* Combination (: SP) should always be in Punct mode */
- } else if ((source[i] == ':') && (source[i + 1] == ' ')) {
+ } else if (source[i] == ':' && source[i + 1] == ' ') {
encode_mode[i + 1] = 'P';
/* Combinations (. SP) and (, SP) sometimes use fewer bits in Digit mode */
- } else if (((source[i] == '.') || (source[i] == ',')) && (source[i + 1] == ' ') && (encode_mode[i] == 'X')) {
- count = az_count_doubles(source, i, src_len);
- next_mode = az_get_next_mode(encode_mode, src_len, i);
+ } else if ((source[i] == '.' || source[i] == ',') && source[i + 1] == ' ' && encode_mode[i] == 'X') {
+ count = az_count_doubles(source, i, length);
+ next_mode = az_get_next_mode(encode_mode, length, i);
if (current_mode == 'U') {
- if ((next_mode == 'D') && (count <= 5)) {
+ if (next_mode == 'D' && count <= 5) {
memset(encode_mode + i, 'D', 2 * count);
}
} else if (current_mode == 'L') {
- if ((next_mode == 'D') && (count <= 4)) {
+ if (next_mode == 'D' && count <= 4) {
memset(encode_mode + i, 'D', 2 * count);
}
} else if (current_mode == 'M') {
- if ((next_mode == 'D') && (count == 1)) {
+ if (next_mode == 'D' && count == 1) {
encode_mode[i] = 'D';
encode_mode[i + 1] = 'D';
}
} else if (current_mode == 'D') {
- if ((next_mode != 'D') && (count <= 4)) {
+ if (next_mode != 'D' && count <= 4) {
memset(encode_mode + i, 'D', 2 * count);
- } else if ((next_mode == 'D') && (count <= 7)) {
+ } else if (next_mode == 'D' && count <= 7) {
memset(encode_mode + i, 'D', 2 * count);
}
}
@@ -177,32 +168,32 @@ static int aztec_text_process(const unsigned char source[], int src_len, int bp,
}
}
- if ((encode_mode[i] != 'X') && (encode_mode[i] != 'B')) {
+ if (encode_mode[i] != 'X' && encode_mode[i] != 'B') {
current_mode = encode_mode[i];
}
}
if (debug_print) {
fputs("First Pass:\n", stdout);
- printf("%.*s\n", src_len, encode_mode);
+ printf("%.*s\n", length, encode_mode);
}
/* Reduce two letter combinations to one codeword marked as [abcd] in Punct mode */
i = 0;
j = 0;
- while (i < src_len) {
+ while (i < length) {
reduced_encode_mode[j] = encode_mode[i];
- if (i + 1 < src_len) {
- if ((source[i] == 13) && (source[i + 1] == 10)) { /* CR LF */
+ if (i + 1 < length) {
+ if (source[i] == 13 && source[i + 1] == 10) { /* CR LF */
reduced_source[j] = 'a';
i += 2;
- } else if ((source[i] == '.') && (source[i + 1] == ' ') && (encode_mode[i] == 'P')) {
+ } else if (source[i] == '.' && source[i + 1] == ' ' && encode_mode[i] == 'P') {
reduced_source[j] = 'b';
i += 2;
- } else if ((source[i] == ',') && (source[i + 1] == ' ') && (encode_mode[i] == 'P')) {
+ } else if (source[i] == ',' && source[i + 1] == ' ' && encode_mode[i] == 'P') {
reduced_source[j] = 'c';
i += 2;
- } else if ((source[i] == ':') && (source[i + 1] == ' ')) {
+ } else if (source[i] == ':' && source[i + 1] == ' ') {
reduced_source[j] = 'd';
i += 2;
} else {
@@ -223,21 +214,20 @@ static int aztec_text_process(const unsigned char source[], int src_len, int bp,
count = az_count_chr(reduced_source, i, reduced_length, 13);
next_mode = az_get_next_mode(reduced_encode_mode, reduced_length, i);
- if ((current_mode == 'U') && ((next_mode == 'U') || (next_mode == 'B')) && (count == 1)) {
+ if (current_mode == 'U' && (next_mode == 'U' || next_mode == 'B') && count == 1) {
reduced_encode_mode[i] = 'P';
- } else if ((current_mode == 'L') && ((next_mode == 'L') || (next_mode == 'B')) && (count == 1)) {
+ } else if (current_mode == 'L' && (next_mode == 'L' || next_mode == 'B') && count == 1) {
reduced_encode_mode[i] = 'P';
- } else if ((current_mode == 'P') || (next_mode == 'P')) {
+ } else if (current_mode == 'P' || next_mode == 'P') {
reduced_encode_mode[i] = 'P';
}
if (current_mode == 'D') {
- if (((next_mode == 'E') || (next_mode == 'U') || (next_mode == 'D') || (next_mode == 'B'))
- && (count <= 2)) {
+ if ((next_mode == 'E' || next_mode == 'U' || next_mode == 'D' || next_mode == 'B') && count <= 2) {
memset(reduced_encode_mode + i, 'P', count);
- } else if ((next_mode == 'L') && (count == 1)) {
+ } else if (next_mode == 'L' && count == 1) {
reduced_encode_mode[i] = 'P';
}
}
@@ -248,32 +238,30 @@ static int aztec_text_process(const unsigned char source[], int src_len, int bp,
}
/* Resolve full stop and comma which can be in Punct or Digit mode */
- } else if ((reduced_source[i] == '.') || (reduced_source[i] == ',')) {
+ } else if (reduced_source[i] == '.' || reduced_source[i] == ',') {
count = az_count_dotcomma(reduced_source, i, reduced_length);
next_mode = az_get_next_mode(reduced_encode_mode, reduced_length, i);
if (current_mode == 'U') {
- if (((next_mode == 'U') || (next_mode == 'L') || (next_mode == 'M') || (next_mode == 'B'))
- && (count == 1)) {
+ if ((next_mode == 'U' || next_mode == 'L' || next_mode == 'M' || next_mode == 'B') && count == 1) {
reduced_encode_mode[i] = 'P';
}
} else if (current_mode == 'L') {
- if ((next_mode == 'L') && (count <= 2)) {
+ if (next_mode == 'L' && count <= 2) {
memset(reduced_encode_mode + i, 'P', count);
- } else if (((next_mode == 'M') || (next_mode == 'B')) && (count == 1)) {
+ } else if ((next_mode == 'M' || next_mode == 'B') && count == 1) {
reduced_encode_mode[i] = 'P';
}
} else if (current_mode == 'M') {
- if (((next_mode == 'E') || (next_mode == 'U') || (next_mode == 'L') || (next_mode == 'M'))
- && (count <= 4)) {
+ if ((next_mode == 'E' || next_mode == 'U' || next_mode == 'L' || next_mode == 'M') && count <= 4) {
memset(reduced_encode_mode + i, 'P', count);
- } else if ((next_mode == 'B') && (count <= 2)) {
+ } else if (next_mode == 'B' && count <= 2) {
memset(reduced_encode_mode + i, 'P', count);
}
- } else if ((current_mode == 'P') && (next_mode != 'D') && (count <= 9)) {
+ } else if (current_mode == 'P' && next_mode != 'D' && count <= 9) {
memset(reduced_encode_mode + i, 'P', count);
}
@@ -288,44 +276,44 @@ static int aztec_text_process(const unsigned char source[], int src_len, int bp,
next_mode = az_get_next_mode(reduced_encode_mode, reduced_length, i);
if (current_mode == 'U') {
- if ((next_mode == 'E') && (count <= 5)) {
+ if (next_mode == 'E' && count <= 5) {
memset(reduced_encode_mode + i, 'U', count);
- } else if (((next_mode == 'U') || (next_mode == 'L') || (next_mode == 'M') || (next_mode == 'P')
- || (next_mode == 'B')) && (count <= 9)) {
+ } else if ((next_mode == 'U' || next_mode == 'L' || next_mode == 'M' || next_mode == 'P'
+ || next_mode == 'B') && count <= 9) {
memset(reduced_encode_mode + i, 'U', count);
}
} else if (current_mode == 'L') {
- if ((next_mode == 'E') && (count <= 5)) {
+ if (next_mode == 'E' && count <= 5) {
memset(reduced_encode_mode + i, 'L', count);
- } else if ((next_mode == 'U') && (count == 1)) {
+ } else if (next_mode == 'U' && count == 1) {
reduced_encode_mode[i] = 'L';
- } else if ((next_mode == 'L') && (count <= 14)) {
+ } else if (next_mode == 'L' && count <= 14) {
memset(reduced_encode_mode + i, 'L', count);
- } else if (((next_mode == 'M') || (next_mode == 'P') || (next_mode == 'B')) && (count <= 9)) {
+ } else if ((next_mode == 'M' || next_mode == 'P' || next_mode == 'B') && count <= 9) {
memset(reduced_encode_mode + i, 'L', count);
}
} else if (current_mode == 'M') {
- if (((next_mode == 'E') || (next_mode == 'U')) && (count <= 9)) {
+ if ((next_mode == 'E' || next_mode == 'U') && count <= 9) {
memset(reduced_encode_mode + i, 'M', count);
- } else if (((next_mode == 'L') || (next_mode == 'B')) && (count <= 14)) {
+ } else if ((next_mode == 'L' || next_mode == 'B') && count <= 14) {
memset(reduced_encode_mode + i, 'M', count);
- } else if (((next_mode == 'M') || (next_mode == 'P')) && (count <= 19)) {
+ } else if ((next_mode == 'M' || next_mode == 'P') && count <= 19) {
memset(reduced_encode_mode + i, 'M', count);
}
} else if (current_mode == 'P') {
- if ((next_mode == 'E') && (count <= 5)) {
+ if (next_mode == 'E' && count <= 5) {
memset(reduced_encode_mode + i, 'U', count);
- } else if (((next_mode == 'U') || (next_mode == 'L') || (next_mode == 'M') || (next_mode == 'P')
- || (next_mode == 'B')) && (count <= 9)) {
+ } else if ((next_mode == 'U' || next_mode == 'L' || next_mode == 'M' || next_mode == 'P'
+ || next_mode == 'B') && count <= 9) {
memset(reduced_encode_mode + i, 'U', count);
}
}
@@ -347,51 +335,51 @@ static int aztec_text_process(const unsigned char source[], int src_len, int bp,
if (reduced_encode_mode[i] != current_mode) {
- for (count = 0; ((i + count) < reduced_length)
- && (reduced_encode_mode[i + count] == reduced_encode_mode[i]); count++);
+ for (count = 0; i + count < reduced_length && reduced_encode_mode[i + count] == reduced_encode_mode[i];
+ count++);
next_mode = az_get_next_mode(reduced_encode_mode, reduced_length, i);
if (reduced_encode_mode[i] == 'P') {
- if ((current_mode == 'U') && (count <= 2)) {
+ if (current_mode == 'U' && count <= 2) {
memset(reduced_encode_mode + i, 'p', count);
- } else if ((current_mode == 'L') && (next_mode != 'U') && (count <= 2)) {
+ } else if (current_mode == 'L' && next_mode != 'U' && count <= 2) {
memset(reduced_encode_mode + i, 'p', count);
- } else if ((current_mode == 'L') && (next_mode == 'U') && (count == 1)) {
+ } else if (current_mode == 'L' && next_mode == 'U' && count == 1) {
reduced_encode_mode[i] = 'p';
- } else if ((current_mode == 'M') && (next_mode != 'M') && (count == 1)) {
+ } else if (current_mode == 'M' && next_mode != 'M' && count == 1) {
reduced_encode_mode[i] = 'p';
- } else if ((current_mode == 'M') && (next_mode == 'M') && (count <= 2)) {
+ } else if (current_mode == 'M' && next_mode == 'M' && count <= 2) {
memset(reduced_encode_mode + i, 'p', count);
- } else if ((current_mode == 'D') && (next_mode != 'D') && (count <= 3)) {
+ } else if (current_mode == 'D' && next_mode != 'D' && count <= 3) {
memset(reduced_encode_mode + i, 'p', count);
- } else if ((current_mode == 'D') && (next_mode == 'D') && (count <= 6)) {
+ } else if (current_mode == 'D' && next_mode == 'D' && count <= 6) {
memset(reduced_encode_mode + i, 'p', count);
}
} else if (reduced_encode_mode[i] == 'U') {
- if ((current_mode == 'L') && ((next_mode == 'L') || (next_mode == 'M')) && (count <= 2)) {
+ if (current_mode == 'L' && (next_mode == 'L' || next_mode == 'M') && count <= 2) {
memset(reduced_encode_mode + i, 'u', count);
- } else if ((current_mode == 'L') && ((next_mode == 'E') || (next_mode == 'D') || (next_mode == 'B')
- || (next_mode == 'P')) && (count == 1)) {
+ } else if (current_mode == 'L' && (next_mode == 'E' || next_mode == 'D' || next_mode == 'B'
+ || next_mode == 'P') && count == 1) {
reduced_encode_mode[i] = 'u';
- } else if ((current_mode == 'D') && (next_mode == 'D') && (count == 1)) {
+ } else if (current_mode == 'D' && next_mode == 'D' && count == 1) {
reduced_encode_mode[i] = 'u';
- } else if ((current_mode == 'D') && (next_mode == 'P') && (count <= 2)) {
+ } else if (current_mode == 'D' && next_mode == 'P' && count <= 2) {
memset(reduced_encode_mode + i, 'u', count);
}
}
}
- if ((reduced_encode_mode[i] != 'p') && (reduced_encode_mode[i] != 'u') && (reduced_encode_mode[i] != 'B')) {
+ if (reduced_encode_mode[i] != 'p' && reduced_encode_mode[i] != 'u' && reduced_encode_mode[i] != 'B') {
current_mode = reduced_encode_mode[i];
}
}
@@ -410,7 +398,7 @@ static int aztec_text_process(const unsigned char source[], int src_len, int bp,
if (eci != 0) {
bp = z_bin_append_posn(0, initial_mode == 'D' ? 4 : 5, binary_string, bp); /* P/S */
bp = z_bin_append_posn(0, 5, binary_string, bp); /* FLG(n) */
- if (eci < 10) {
+ if (eci <= 9) {
bp = z_bin_append_posn(1, 3, binary_string, bp); /* FLG(1) */
bp = z_bin_append_posn(2 + eci, 4, binary_string, bp);
} else if (eci <= 99) {
@@ -579,7 +567,7 @@ static int aztec_text_process(const unsigned char source[], int src_len, int bp,
/* Byte mode - process full block here */
if (reduced_encode_mode[i] == 'B') {
int big_batch = 0;
- for (count = 0; ((i + count) < reduced_length) && (reduced_encode_mode[i + count] == 'B'); count++);
+ for (count = 0; i + count < reduced_length && reduced_encode_mode[i + count] == 'B'; count++);
if (count > 2047 + 2078) { /* Can't be more than 19968 / 8 = 2496 */
return 0;
@@ -614,12 +602,12 @@ static int aztec_text_process(const unsigned char source[], int src_len, int bp,
continue;
}
- if ((reduced_encode_mode[i] != 'u') && (reduced_encode_mode[i] != 'p')) {
+ if (reduced_encode_mode[i] != 'u' && reduced_encode_mode[i] != 'p') {
current_mode = reduced_encode_mode[i];
}
}
- if ((reduced_encode_mode[i] == 'U') || (reduced_encode_mode[i] == 'u')) {
+ if (reduced_encode_mode[i] == 'U' || reduced_encode_mode[i] == 'u') {
if (reduced_source[i] == ' ') {
if (!(bp = az_bin_append_posn(1, 5, binary_string, bp))) return 0; /* SP */
} else {
@@ -639,7 +627,7 @@ static int aztec_text_process(const unsigned char source[], int src_len, int bp,
} else {
if (!(bp = az_bin_append_posn(AztecSymbolChar[reduced_source[i]], 5, binary_string, bp))) return 0;
}
- } else if ((reduced_encode_mode[i] == 'P') || (reduced_encode_mode[i] == 'p')) {
+ } else if (reduced_encode_mode[i] == 'P' || reduced_encode_mode[i] == 'p') {
if (gs1 && reduced_source[i] == '\x1D') {
if (!(bp = az_bin_append_posn(0, 5, binary_string, bp))) return 0; /* FLG(n) */
if (!(bp = az_bin_append_posn(0, 3, binary_string, bp))) return 0; /* FLG(0) = FNC1 */
@@ -806,7 +794,7 @@ static int az_bitrun_stuff(const char *binary_string, const int data_length, con
/* 7.3.1.2 "whenever the first B-1 bits ... are all “0”s, then a dummy “1” is inserted..."
"Similarly a message codeword that starts with B-1 “1”s has a dummy “0” inserted..." */
- if (count == 0 || count == (codeword_size - 1)) {
+ if (count == 0 || count == codeword_size - 1) {
/* Codeword of B-1 '0's or B-1 '1's */
if (j > data_maxsize) {
return 0; /* Fail */
@@ -975,7 +963,7 @@ INTERNAL int zint_aztec(struct zint_symbol *symbol, struct zint_seg segs[], cons
/* For each level of error correction work out the smallest symbol which the data will fit in */
for (i = compact_loop_start; i > 0; i--) {
- if ((data_length + adjustment_size) <= AztecCompactDataSizes[ecc_level - 1][i - 1]) {
+ if (data_length + adjustment_size <= AztecCompactDataSizes[ecc_level - 1][i - 1]) {
layers = i;
compact = 1;
data_maxsize = AztecCompactDataSizes[ecc_level - 1][i - 1];
@@ -983,7 +971,7 @@ INTERNAL int zint_aztec(struct zint_symbol *symbol, struct zint_seg segs[], cons
}
if (!compact) {
for (i = 32; i > 0; i--) {
- if ((data_length + adjustment_size) <= AztecDataSizes[ecc_level - 1][i - 1]) {
+ if (data_length + adjustment_size <= AztecDataSizes[ecc_level - 1][i - 1]) {
layers = i;
compact = 0;
data_maxsize = AztecDataSizes[ecc_level - 1][i - 1];
@@ -1037,7 +1025,7 @@ INTERNAL int zint_aztec(struct zint_symbol *symbol, struct zint_seg segs[], cons
symbol->option_2 = compact ? layers : layers + 4; /* Feedback options */
} else { /* The size of the symbol has been specified by the user */
- if ((symbol->option_2 < 0) || (symbol->option_2 > 36)) {
+ if (symbol->option_2 < 0 || symbol->option_2 > 36) {
return z_errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 510, "Version '%d' out of range (1 to 36)",
symbol->option_2);
}
@@ -1105,7 +1093,7 @@ INTERNAL int zint_aztec(struct zint_symbol *symbol, struct zint_seg segs[], cons
fputc('\n', stdout);
}
- if (reader_init && (layers > 22)) {
+ if (reader_init && layers > 22) {
return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 506,
"Input too long for Reader Initialisation, requires %d layers (maximum 22)", layers);
}
diff --git a/backend/channel.c b/backend/channel.c
index fb29c3bb..55fb5b1e 100644
--- a/backend/channel.c
+++ b/backend/channel.c
@@ -192,7 +192,7 @@ INTERNAL int zint_channel(struct zint_symbol *symbol, unsigned char source[], in
}
target_value = z_to_int(source, length);
- if ((symbol->option_2 < 3) || (symbol->option_2 > 8)) {
+ if (symbol->option_2 < 3 || symbol->option_2 > 8) {
channels = 0;
} else {
channels = symbol->option_2;
diff --git a/backend/codabar.c b/backend/codabar.c
index e0fb4b4e..4e79b861 100644
--- a/backend/codabar.c
+++ b/backend/codabar.c
@@ -71,12 +71,11 @@ INTERNAL int zint_codabar(struct zint_symbol *symbol, unsigned char source[], in
z_to_upper(source, length);
/* Codabar must begin and end with the characters A, B, C or D */
- if ((source[0] != 'A') && (source[0] != 'B') && (source[0] != 'C')
- && (source[0] != 'D')) {
+ if (source[0] != 'A' && source[0] != 'B' && source[0] != 'C' && source[0] != 'D') {
return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 358, "Does not begin with \"A\", \"B\", \"C\" or \"D\"");
}
- if ((source[length - 1] != 'A') && (source[length - 1] != 'B') &&
- (source[length - 1] != 'C') && (source[length - 1] != 'D')) {
+ if (source[length - 1] != 'A' && source[length - 1] != 'B' && source[length - 1] != 'C'
+ && source[length - 1] != 'D') {
return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 359, "Does not end with \"A\", \"B\", \"C\" or \"D\"");
}
if ((i = z_not_sane_lookup(CALCIUM, sizeof(CALCIUM) - 1, source, length, posns))) {
diff --git a/backend/code.c b/backend/code.c
index 2e91ea64..913b9b64 100644
--- a/backend/code.c
+++ b/backend/code.c
@@ -129,15 +129,15 @@ INTERNAL int zint_code39(struct zint_symbol *symbol, unsigned char source[], int
int error_number = 0;
const int raw_text = symbol->output_options & BARCODE_RAW_TEXT;
- if ((symbol->option_2 < 0) || (symbol->option_2 > 2)) {
+ if (symbol->option_2 < 0 || symbol->option_2 > 2) {
symbol->option_2 = 0;
}
/* LOGMARS MIL-STD-1189 Rev. B https://apps.dtic.mil/dtic/tr/fulltext/u2/a473534.pdf */
- if ((symbol->symbology == BARCODE_LOGMARS) && (length > 30)) { /* MIL-STD-1189 Rev. B Section 5.2.6.2 */
+ if (symbol->symbology == BARCODE_LOGMARS && length > 30) { /* MIL-STD-1189 Rev. B Section 5.2.6.2 */
return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 322, "Input length %d too long (maximum 30)", length);
/* Prevent encoded_data out-of-bounds >= 143 for BARCODE_HIBC_39 due to wider 'wide' bars */
- } else if ((symbol->symbology == BARCODE_HIBC_39) && (length > 70)) { /* 16 (Start) + 70*16 + 15 (Stop) = 1151 */
+ } else if (symbol->symbology == BARCODE_HIBC_39 && length > 70) { /* 16 (Start) + 70*16 + 15 (Stop) = 1151 */
/* 70 less '+' and check */
return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 319, "Input length %d too long (maximum 68)", length - 2);
} else if (length > 86) { /* 13 (Start) + 86*13 + 12 (Stop) = 1143 */
@@ -172,7 +172,7 @@ INTERNAL int zint_code39(struct zint_symbol *symbol, unsigned char source[], int
memcpy(d, C39Table[43], 9);
d += 9;
- if ((symbol->symbology == BARCODE_LOGMARS) || (symbol->symbology == BARCODE_HIBC_39)) {
+ if (symbol->symbology == BARCODE_LOGMARS || symbol->symbology == BARCODE_HIBC_39) {
/* LOGMARS and HIBC use wider 'wide' bars than normal Code 39 */
counter = d - dest;
for (i = 0; i < counter; i++) {
diff --git a/backend/code16k.c b/backend/code16k.c
index 0ff2e822..e0c03fe7 100644
--- a/backend/code16k.c
+++ b/backend/code16k.c
@@ -71,7 +71,7 @@ static int c16k_parunmodd(const unsigned char llyth, const int check_fnc1) {
if (llyth <= 31) {
modd = check_fnc1 && llyth == '\x1D' ? C16K_ABORC : C16K_SHIFTA;
- } else if ((llyth >= 48) && (llyth <= 57)) {
+ } else if (llyth >= 48 && llyth <= 57) {
modd = C16K_ABORC;
} else if (llyth <= 95) {
modd = C16K_AORB;
@@ -136,7 +136,7 @@ static void c16k_dxsmooth(int list[2][C128_MAX], int *p_indexliste) {
if (i == 0) { /* First block */
if (current == C16K_ABORC) {
- if ((indexliste == 1) && (length == 2)) {
+ if (indexliste == 1 && length == 2) {
/* Rule 1a */
list[1][i] = C16K_LATCHC;
current = C16K_LATCHC;
@@ -362,7 +362,7 @@ INTERNAL int zint_code16k(struct zint_symbol *symbol, unsigned char source[], in
do {
list[1][indexliste] = mode;
- while ((list[1][indexliste] == mode) && (indexchaine < length)) {
+ while (list[1][indexliste] == mode && indexchaine < length) {
list[0][indexliste]++;
indexchaine++;
if (indexchaine == length) {
@@ -393,7 +393,7 @@ INTERNAL int zint_code16k(struct zint_symbol *symbol, unsigned char source[], in
}
if (m == 2) {
m = 5;
- } else if ((set[0] == 'B') && (set[1] == 'C') && fset[0] != 'f') {
+ } else if (set[0] == 'B' && set[1] == 'C' && fset[0] != 'f') {
m = 6;
}
values[1] = 96; /* FNC3 */
@@ -406,9 +406,9 @@ INTERNAL int zint_code16k(struct zint_symbol *symbol, unsigned char source[], in
case 'C': m = 4; break;
}
} else {
- if ((set[0] == 'B') && (set[1] == 'C')) {
+ if (set[0] == 'B' && set[1] == 'C') {
m = fset[0] == 'f' ? 6 : 5;
- } else if ((set[0] == 'B') && (set[1] == 'B') && (set[2] == 'C') && fset[0] != 'f' && fset[1] != 'f') {
+ } else if (set[0] == 'B' && set[1] == 'B' && set[2] == 'C' && fset[0] != 'f' && fset[1] != 'f') {
m = 6;
}
}
@@ -422,7 +422,7 @@ INTERNAL int zint_code16k(struct zint_symbol *symbol, unsigned char source[], in
/* TODO: make use of extra (non-CODE128) shifts: 1SB, 2SA/B/C, 3SB/C */
do {
- if ((read != 0) && (set[read] != current_set)) {
+ if (read != 0 && set[read] != current_set) {
/* Latch different code set */
switch (set[read]) {
case 'A':
@@ -455,7 +455,7 @@ INTERNAL int zint_code16k(struct zint_symbol *symbol, unsigned char source[], in
}
}
- if ((set[read] == 'a') || (set[read] == 'b')) {
+ if (set[read] == 'a' || set[read] == 'b') {
/* Insert shift character */
values[bar_characters++] = 98;
}
@@ -492,7 +492,7 @@ INTERNAL int zint_code16k(struct zint_symbol *symbol, unsigned char source[], in
if (pads_needed == 5) {
pads_needed = 0;
}
- if ((bar_characters + pads_needed) < 8) {
+ if (bar_characters + pads_needed < 8) {
pads_needed += 8 - (bar_characters + pads_needed);
}
diff --git a/backend/code49.c b/backend/code49.c
index 62282404..b60b4751 100644
--- a/backend/code49.c
+++ b/backend/code49.c
@@ -97,7 +97,7 @@ INTERNAL int zint_code49(struct zint_symbol *symbol, unsigned char source[], int
block_remain = j % 5;
for (c = 0; c < block_count; c++) {
- if ((c == block_count - 1) && (block_remain == 2)) {
+ if (c == block_count - 1 && block_remain == 2) {
/* Rule (d) */
block_value = 100000 + z_to_int(ZCUCP(intermediate + i), 4);
@@ -207,7 +207,7 @@ INTERNAL int zint_code49(struct zint_symbol *symbol, unsigned char source[], int
rows = 0;
do {
for (i = 0; i < 7; i++) {
- if (((rows * 7) + i) < codeword_count) {
+ if (rows * 7 + i < codeword_count) {
c_grid[rows][i] = codewords[(rows * 7) + i];
} else {
c_grid[rows][i] = 48; /* Pad */
@@ -215,9 +215,9 @@ INTERNAL int zint_code49(struct zint_symbol *symbol, unsigned char source[], int
}
}
rows++;
- } while ((rows * 7) < codeword_count);
+ } while (rows * 7 < codeword_count);
- if ((((rows <= 6) && (pad_count < 5))) || (rows > 6) || (rows == 1)) {
+ if ((rows <= 6 && pad_count < 5) || rows > 6 || rows == 1) {
/* Add a row */
for (i = 0; i < 7; i++) {
c_grid[rows][i] = 48; /* Pad */
@@ -328,7 +328,7 @@ INTERNAL int zint_code49(struct zint_symbol *symbol, unsigned char source[], int
bp = 0;
bp = z_bin_append_posn(2, 2, pattern, bp); /* Start character "10" */
for (j = 0; j < 4; j++) {
- if (i != (rows - 1)) {
+ if (i != rows - 1) {
if (c49_table4[i][j] == 'E') {
/* Even Parity */
bp = z_bin_append_posn(c49_even_bitpattern[w_grid[i][j]], 16, pattern, bp);
diff --git a/backend/common.c b/backend/common.c
index 10ee46d9..b89bad6c 100644
--- a/backend/common.c
+++ b/backend/common.c
@@ -39,9 +39,9 @@
INTERNAL int z_ctoi(const char source) {
if (z_isdigit(source))
return (source - '0');
- if ((source >= 'A') && (source <= 'F'))
+ if (source >= 'A' && source <= 'F')
return (source - 'A' + 10);
- if ((source >= 'a') && (source <= 'f'))
+ if (source >= 'a' && source <= 'f')
return (source - 'a' + 10);
return -1;
}
@@ -662,7 +662,7 @@ INTERNAL int z_is_fixed_ratio(const int symbology) {
/* Whether next two characters are digits */
INTERNAL int z_is_twodigits(const unsigned char source[], const int length, const int position) {
- if ((position + 1 < length) && z_isdigit(source[position]) && z_isdigit(source[position + 1])) {
+ if (position + 1 < length && z_isdigit(source[position]) && z_isdigit(source[position + 1])) {
return 1;
}
@@ -719,7 +719,7 @@ INTERNAL unsigned int z_decode_utf8(unsigned int *state, unsigned int *codep, co
const unsigned int type = utf8d[byte];
- *codep = *state != 0 ? (byte & 0x3fu) | (*codep << 6) : (0xff >> type) & byte;
+ *codep = *state != 0 ? (byte & 0x3Fu) | (*codep << 6) : (0xFF >> type) & byte;
*state = utf8d[256 + *state + type];
@@ -759,7 +759,7 @@ INTERNAL int z_utf8_to_unicode(struct zint_symbol *symbol, const unsigned char s
if (state != 0) {
return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 240, "Corrupt Unicode data");
}
- if (disallow_4byte && codepoint > 0xffff) {
+ if (disallow_4byte && codepoint > 0xFFFF) {
return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 242,
"Unicode sequences of more than 3 bytes not supported");
}
diff --git a/backend/composite.c b/backend/composite.c
index c387fdcf..37fe7541 100644
--- a/backend/composite.c
+++ b/backend/composite.c
@@ -1449,9 +1449,9 @@ INTERNAL int zint_composite(struct zint_symbol *symbol, unsigned char source[],
}
}
}
- if ((linear->width + bottom_shift) > symbol->width + top_shift) {
+ if (linear->width + bottom_shift > symbol->width + top_shift) {
symbol->width = linear->width + bottom_shift;
- } else if ((symbol->width + top_shift) > linear->width + bottom_shift) {
+ } else if (symbol->width + top_shift > linear->width + bottom_shift) {
symbol->width += top_shift;
}
symbol->rows += linear->rows;
diff --git a/backend/dmatrix.c b/backend/dmatrix.c
index e7639325..03964f96 100644
--- a/backend/dmatrix.c
+++ b/backend/dmatrix.c
@@ -402,7 +402,7 @@ static int dm_look_ahead_test(const unsigned char source[], const int length, co
}
cnt_1 = b256_count + DM_MULT_1;
if (cnt_1 <= ascii_count || (cnt_1 < edf_count && cnt_1 < text_count && cnt_1 < x12_count
- && cnt_1 < c40_count)) {
+ && cnt_1 < c40_count)) {
if (debug_print) fputs("BAS->", stdout);
return DM_BASE256; /* step (r)(2) */
}
@@ -535,7 +535,7 @@ static int dm_edi_buffer_xfer(int process_buffer[8], int process_p, unsigned cha
for (i = 0; i < process_e; i += 4) {
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);
+ target[tp++] = (unsigned char) ((process_buffer[i + 1] & 0x0F) << 4 | (process_buffer[i + 2] & 0x3C) >> 2);
target[tp++] = (unsigned char) ((process_buffer[i + 2] & 0x03) << 6 | process_buffer[i + 3]);
if (debug_print) {
printf("[%d %d %d %d (%d %d %d)] ", process_buffer[i], process_buffer[i + 1], process_buffer[i + 2],
@@ -550,8 +550,8 @@ static int dm_edi_buffer_xfer(int process_buffer[8], int process_p, unsigned cha
if (empty) {
if (process_p == 3) {
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);
+ target[tp++] = (unsigned char) ((process_buffer[i + 1] & 0x0F) << 4
+ | (process_buffer[i + 2] & 0x3C) >> 2);
target[tp++] = (unsigned char) ((process_buffer[i + 2] & 0x03) << 6);
if (debug_print) {
printf("[%d %d %d (%d %d %d)] ", process_buffer[i], process_buffer[i + 1], process_buffer[i + 2],
@@ -559,7 +559,7 @@ static int dm_edi_buffer_xfer(int process_buffer[8], int process_p, unsigned cha
}
} else if (process_p == 2) {
target[tp++] = (unsigned char) (process_buffer[i] << 2 | (process_buffer[i + 1] & 0x30) >> 4);
- target[tp++] = (unsigned char) ((process_buffer[i + 1] & 0x0f) << 4);
+ target[tp++] = (unsigned char) ((process_buffer[i + 1] & 0x0F) << 4);
if (debug_print) {
printf("[%d %d (%d %d)] ", process_buffer[i], process_buffer[i + 1], target[tp - 2],
target[tp - 1]);
@@ -582,7 +582,7 @@ static int dm_edi_buffer_xfer(int process_buffer[8], int process_p, unsigned cha
static int dm_get_symbolsize(struct zint_symbol *symbol, const int minimum) {
int i;
- if ((symbol->option_2 >= 1) && (symbol->option_2 <= DMSIZESCOUNT)) {
+ if (symbol->option_2 >= 1 && symbol->option_2 <= DMSIZESCOUNT) {
return dm_intsymbol[symbol->option_2 - 1];
}
if (minimum > 1304) {
@@ -1098,7 +1098,7 @@ static int dm_minimalenc(struct zint_symbol *symbol, const unsigned char source[
tp = dm_update_b256_field_length(target, tp, *p_b256_start);
/* B.2.1 255-state randomising algorithm */
for (i = *p_b256_start; i < tp; i++) {
- const int prn = ((149 * (i + 1)) % 255) + 1;
+ const int prn = (149 * (i + 1)) % 255 + 1;
target[i] = (unsigned char) ((target[i] + prn) & 0xFF);
}
break;
@@ -1457,7 +1457,7 @@ static int dm_isoenc(struct zint_symbol *symbol, const unsigned char source[], c
tp = dm_update_b256_field_length(target, tp, *p_b256_start);
/* B.2.1 255-state randomising algorithm */
for (i = *p_b256_start; i < tp; i++) {
- const int prn = ((149 * (i + 1)) % 255) + 1;
+ const int prn = (149 * (i + 1)) % 255 + 1;
target[i] = (unsigned char) ((target[i] + prn) & 0xFF);
}
/* We switch directly here to avoid flipping back to Base 256 due to `dm_text_sp_cnt()` */
@@ -1607,7 +1607,7 @@ static int dm_encode(struct zint_symbol *symbol, const unsigned char source[], c
} else if (current_mode == DM_X12) {
if (debug_print) fputs("X12 ", stdout);
- if ((symbols_left == 1) && (process_p == 1)) {
+ if (symbols_left == 1 && process_p == 1) {
/* Unlatch not required! */
target[tp++] = source[length - 1] + 1;
if (debug_print) printf("A%02X ", target[tp - 1] - 1);
@@ -1652,7 +1652,7 @@ static int dm_encode(struct zint_symbol *symbol, const unsigned char source[], c
}
/* B.2.1 255-state randomising algorithm */
for (i = b256_start; i < tp; i++) {
- int prn = ((149 * (i + 1)) % 255) + 1;
+ const int prn = (149 * (i + 1)) % 255 + 1;
target[i] = (unsigned char) ((target[i] + prn) & 0xFF);
}
}
@@ -1833,15 +1833,15 @@ static int dm_encode_segs(struct zint_symbol *symbol, struct zint_seg segs[], co
/* add pad bits */
static void dm_add_tail(unsigned char target[], int tp, const int tail_length) {
- int i, prn, temp;
+ int i;
target[tp++] = 129; /* Pad */
for (i = 1; i < tail_length; i++) {
/* B.1.1 253-state randomising algorithm */
- prn = ((149 * (tp + 1)) % 253) + 1;
- temp = 129 + prn;
+ const int prn = (149 * (tp + 1)) % 253 + 1;
+ const int temp = 129 + prn;
if (temp <= 254) {
- target[tp++] = (unsigned char) (temp);
+ target[tp++] = (unsigned char) temp;
} else {
target[tp++] = (unsigned char) (temp - 254);
}
@@ -1866,7 +1866,7 @@ static int dm_ecc200(struct zint_symbol *symbol, struct zint_seg segs[], const i
symbolsize = dm_get_symbolsize(symbol, binlen);
if (binlen > dm_matrixbytes[symbolsize]) {
- if ((symbol->option_2 >= 1) && (symbol->option_2 <= DMSIZESCOUNT)) {
+ if (symbol->option_2 >= 1 && symbol->option_2 <= DMSIZESCOUNT) {
/* The symbol size was given by --ver (option_2) */
return ZEXT z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 522,
"Input too long for Version %1$d, requires %2$d codewords (maximum %3$d)",
diff --git a/backend/dotcode.c b/backend/dotcode.c
index 6913845f..93a0e2cf 100644
--- a/backend/dotcode.c
+++ b/backend/dotcode.c
@@ -453,8 +453,8 @@ static int dc_ahead_b(const unsigned char source[], const int length, const int
int count = 0;
int i, incr;
- for (i = position; i < length && (incr = dc_datum_b(source, length, i))
- && dc_try_c(source, length, i) < 2; i += incr) {
+ for (i = position; i < length && (incr = dc_datum_b(source, length, i)) && dc_try_c(source, length, i) < 2;
+ i += incr) {
count++;
}
@@ -545,8 +545,8 @@ static int dc_encode_message(struct zint_symbol *symbol, const unsigned char sou
} else if (length > 5) { /* Note assuming macro headers don't straddle segments */
/* Step C1 */
if (source[0] == '[' && source[1] == ')' && source[2] == '>' && source[3] == 30 /*RS*/ && last_EOT) {
- int format_050612 = (source[4] == '0' && (source[5] == '5' || source[5] == '6'))
- || (source[4] == '1' && source[5] == '2');
+ const int format_050612 = (source[4] == '0' && (source[5] == '5' || source[5] == '6'))
+ || (source[4] == '1' && source[5] == '2');
inside_macro = 0;
if (length > 6 && format_050612 && source[6] == 29 /*GS*/ && last_RSEOT) {
if (source[5] == '5') {
@@ -613,7 +613,7 @@ static int dc_encode_message(struct zint_symbol *symbol, const unsigned char sou
while (position < length) {
/* Step A */
- if (last_seg && (position == length - 2) && (inside_macro != 0) && (inside_macro != 100)) {
+ if (last_seg && position == length - 2 && inside_macro != 0 && inside_macro != 100) {
/* inside_macro only gets set to 97, 98 or 99 if the last two characters are RS/EOT */
position += 2;
if (debug_print) fputs("A ", stdout);
@@ -621,7 +621,7 @@ static int dc_encode_message(struct zint_symbol *symbol, const unsigned char sou
}
/* Step B */
- if (last_seg && (position == length - 1) && (inside_macro == 100)) {
+ if (last_seg && position == length - 1 && inside_macro == 100) {
/* inside_macro only gets set to 100 if the last character is EOT */
position++;
if (debug_print) fputs("B ", stdout);
@@ -657,7 +657,7 @@ static int dc_encode_message(struct zint_symbol *symbol, const unsigned char sou
if (dc_binary(source, length, position)) {
/* z_cnt_digits(position + 1) > 0 */
if (position + 1 < length && z_isdigit(source[position + 1])) {
- if ((source[position] - 128) < 32) {
+ if (source[position] - 128 < 32) {
codeword_array[ap++] = 110; /* Upper Shift A */
codeword_array[ap++] = source[position] - 128 + 64;
} else {
@@ -740,7 +740,7 @@ static int dc_encode_message(struct zint_symbol *symbol, const unsigned char sou
if (dc_datum_b(source, length, position)) {
int done = 0;
- if ((source[position] >= 32) && (source[position] <= 127)) {
+ if (source[position] >= 32 && source[position] <= 127) {
codeword_array[ap++] = source[position] - 32;
done = 1;
@@ -772,7 +772,7 @@ static int dc_encode_message(struct zint_symbol *symbol, const unsigned char sou
/* Step D3 */
if (dc_binary(source, length, position)) {
if (dc_datum_b(source, length, position + 1)) {
- if ((source[position] - 128) < 32) {
+ if (source[position] - 128 < 32) {
codeword_array[ap++] = 110; /* Bin Shift A */
codeword_array[ap++] = source[position] - 128 + 64;
} else {
@@ -845,7 +845,7 @@ static int dc_encode_message(struct zint_symbol *symbol, const unsigned char sou
/* Step E3 */
if (dc_binary(source, length, position)) {
if (dc_datum_a(source, length, position + 1)) {
- if ((source[position] - 128) < 32) {
+ if (source[position] - 128 < 32) {
codeword_array[ap++] = 110; /* Bin Shift A */
codeword_array[ap++] = source[position] - 128 + 64;
} else {
@@ -1044,37 +1044,34 @@ static int dc_make_dotstream(const unsigned char masked_array[], const int array
static int dc_is_corner(const int column, const int row, const int width, const int height) {
/* Top Left */
- if ((column == 0) && (row == 0)) {
+ if (column == 0 && row == 0) {
return 1;
}
/* Top Right */
if (height & 1) {
- if (((column == width - 2) && (row == 0))
- || ((column == width - 1) && (row == 1))) {
+ if ((column == width - 2 && row == 0) || (column == width - 1 && row == 1)) {
return 1;
}
} else {
- if ((column == width - 1) && (row == 0)) {
+ if (column == width - 1 && row == 0) {
return 1;
}
}
/* Bottom Left */
if (height & 1) {
- if ((column == 0) && (row == height - 1)) {
+ if (column == 0 && row == height - 1) {
return 1;
}
} else {
- if (((column == 0) && (row == height - 2))
- || ((column == 1) && (row == height - 1))) {
+ if ((column == 0 && row == height - 2) || (column == 1 && row == height - 1)) {
return 1;
}
}
/* Bottom Right */
- if (((column == width - 2) && (row == height - 1))
- || ((column == width - 1) && (row == height - 2))) {
+ if ((column == width - 2 && row == height - 1) || (column == width - 1 && row == height - 2)) {
return 1;
}
@@ -1296,26 +1293,26 @@ INTERNAL int zint_dotcode(struct zint_symbol *symbol, struct zint_seg segs[], co
width = (int) w;
if (((width + height) & 1) == 1) {
- if ((width * height) < min_area) {
+ if (width * height < min_area) {
width++;
height++;
}
} else {
- if ((h * width) < (w * height)) {
+ if (h * width < w * height) {
width++;
- if ((width * height) < min_area) {
+ if (width * height < min_area) {
width--;
height++;
- if ((width * height) < min_area) {
+ if (width * height < min_area) {
width += 2;
}
}
} else {
height++;
- if ((width * height) < min_area) {
+ if (width * height < min_area) {
width++;
height--;
- if ((width * height) < min_area) {
+ if (width * height < min_area) {
height += 2;
}
}
diff --git a/backend/filemem.c b/backend/filemem.c
index 5ce112f1..65bfbc7a 100644
--- a/backend/filemem.c
+++ b/backend/filemem.c
@@ -261,11 +261,10 @@ static int fm_vprintf(struct filemem *restrict const fmp, const char *fmt, va_li
#endif
va_copy(cpy, ap);
- /* The clang-tidy warning is a bug https://github.com/llvm/llvm-project/issues/40656 */
#ifdef FM_NO_VSNPRINTF
- size = vfprintf(fmp->fp_null, fmt, cpy); /* NOLINT(clang-analyzer-valist.Uninitialized) */
+ size = vfprintf(fmp->fp_null, fmt, cpy);
#else
- size = vsnprintf(NULL, 0, fmt, cpy); /* NOLINT(clang-analyzer-valist.Uninitialized) */
+ size = vsnprintf(NULL, 0, fmt, cpy);
#endif
va_end(cpy);
@@ -278,10 +277,8 @@ static int fm_vprintf(struct filemem *restrict const fmp, const char *fmt, va_li
}
#ifdef FM_NO_VSNPRINTF
- /* NOLINTNEXTLINE(clang-analyzer-valist.Uninitialized) - see above */
check = vsprintf((char *) fmp->mem + fmp->mempos, fmt, ap);
#else
- /* NOLINTNEXTLINE(clang-analyzer-valist.Uninitialized) - see above */
check = vsnprintf((char *) fmp->mem + fmp->mempos, size + 1, fmt, ap);
#endif
@@ -309,7 +306,7 @@ INTERNAL int zint_fm_printf(struct filemem *restrict const fmp, const char *fmt,
return ret;
}
va_start(ap, fmt);
- ret = vfprintf(fmp->fp, fmt, ap) >= 0; /* NOLINT(clang-analyzer-valist.Uninitialized) - see above */
+ ret = vfprintf(fmp->fp, fmt, ap) >= 0;
va_end(ap);
return ret ? 1 : fm_seterr(fmp, errno);
}
diff --git a/backend/gridmtx.c b/backend/gridmtx.c
index d695a100..fcb24db1 100644
--- a/backend/gridmtx.c
+++ b/backend/gridmtx.c
@@ -456,22 +456,22 @@ static int gm_encode(unsigned int ddata[], const int length, char binary[], cons
switch (current_mode) {
case GM_CHINESE:
done = 0;
- if (ddata[sp] > 0xff) {
+ if (ddata[sp] > 0xFF) {
/* GB2312 character */
- c1 = (ddata[sp] & 0xff00) >> 8;
- c2 = ddata[sp] & 0xff;
+ c1 = (ddata[sp] & 0xFF00) >> 8;
+ c2 = ddata[sp] & 0xFF;
- if ((c1 >= 0xa1) && (c1 <= 0xa9)) {
- glyph = (0x60 * (c1 - 0xa1)) + (c2 - 0xa0);
- } else if ((c1 >= 0xb0) && (c1 <= 0xf7)) {
- glyph = (0x60 * (c1 - 0xb0 + 9)) + (c2 - 0xa0);
+ if (c1 >= 0xA1 && c1 <= 0xA9) {
+ glyph = 0x60 * (c1 - 0xA1) + (c2 - 0xA0);
+ } else if (c1 >= 0xB0 && c1 <= 0xF7) {
+ glyph = 0x60 * (c1 - 0xB0 + 9) + (c2 - 0xA0);
}
done = 1; /* GB 2312 always within above ranges */
/* Note not using the unallocated glyphs 7776 to 8191 mentioned in AIMD014 section 6.3.1.2 */
}
- if (!(done)) {
- if (sp != (length - 1)) {
- if ((ddata[sp] == 13) && (ddata[sp + 1] == 10)) {
+ if (!done) {
+ if (sp != length - 1) {
+ if (ddata[sp] == 13 && ddata[sp + 1] == 10) {
/* End of Line */
glyph = 7776;
sp++;
@@ -479,8 +479,8 @@ static int gm_encode(unsigned int ddata[], const int length, char binary[], cons
}
}
}
- if (!(done)) {
- if (sp != (length - 1)) {
+ if (!done) {
+ if (sp != length - 1) {
if (z_isdigit(ddata[sp]) && z_isdigit(ddata[sp + 1])) {
/* Two digits */
glyph = 8033 + (10 * (ddata[sp] - '0')) + (ddata[sp + 1] - '0');
@@ -489,7 +489,7 @@ static int gm_encode(unsigned int ddata[], const int length, char binary[], cons
}
}
}
- if (!(done)) {
+ if (!done) {
/* Byte value */
glyph = 7777 + ddata[sp];
}
@@ -527,7 +527,7 @@ static int gm_encode(unsigned int ddata[], const int length, char binary[], cons
}
punt = ddata[sp];
ppos = p;
- } else if (sp < (length - 1) && (ddata[sp] == 13) && (ddata[sp + 1] == 10)) {
+ } else if (sp < length - 1 && ddata[sp] == 13 && ddata[sp + 1] == 10) {
/* */
if (ppos != -1) {
break;
@@ -539,7 +539,7 @@ static int gm_encode(unsigned int ddata[], const int length, char binary[], cons
break;
}
sp++;
- } while ((p < 3) && (sp < length) && mode[sp] == GM_NUMBER);
+ } while (p < 3 && sp < length && mode[sp] == GM_NUMBER);
if (ppos != -1) {
switch (punt) {
@@ -804,7 +804,7 @@ static void gm_add_ecc(const char binary[], const int data_posn, const int layer
data[data_posn] = 0x00;
for (i = (data_posn + 1); i < data_cw; i++) {
if (i & 1) {
- data[i] = 0x7e;
+ data[i] = 0x7E;
} else {
data[i] = 0x00;
}
@@ -1097,7 +1097,7 @@ INTERNAL int zint_gridmatrix(struct zint_symbol *symbol, struct zint_seg segs[],
}
layers = auto_layers;
- if ((symbol->option_2 >= 1) && (symbol->option_2 <= 13)) {
+ if (symbol->option_2 >= 1 && symbol->option_2 <= 13) {
input_latch = 1;
if (symbol->option_2 >= min_layers) {
layers = symbol->option_2;
@@ -1111,7 +1111,7 @@ INTERNAL int zint_gridmatrix(struct zint_symbol *symbol, struct zint_seg segs[],
auto_ecc_level = 3;
if (layers == 1) {
auto_ecc_level = 5;
- } else if ((layers == 2) || (layers == 3)) {
+ } else if (layers == 2 || layers == 3) {
auto_ecc_level = 4;
}
ecc_level = auto_ecc_level;
@@ -1123,26 +1123,25 @@ INTERNAL int zint_gridmatrix(struct zint_symbol *symbol, struct zint_seg segs[],
min_ecc_level = 2;
}
- if ((symbol->option_1 >= 1) && (symbol->option_1 <= 5)) {
+ if (symbol->option_1 >= 1 && symbol->option_1 <= 5) {
if (symbol->option_1 >= min_ecc_level) {
ecc_level = symbol->option_1;
} else {
ecc_level = min_ecc_level;
}
}
- if (data_cw > gm_data_codewords[(5 * (layers - 1)) + (ecc_level - 1)]) {
+ if (data_cw > gm_data_codewords[5 * (layers - 1) + (ecc_level - 1)]) {
/* If layers user-specified (option_2), try reducing ECC level first */
if (input_latch && ecc_level > min_ecc_level) {
do {
ecc_level--;
- } while ((data_cw > gm_data_codewords[(5 * (layers - 1)) + (ecc_level - 1)])
- && (ecc_level > min_ecc_level));
+ } while (data_cw > gm_data_codewords[5 * (layers - 1) + (ecc_level - 1)] && ecc_level > min_ecc_level);
}
- while (data_cw > gm_data_codewords[(5 * (layers - 1)) + (ecc_level - 1)] && (layers < 13)) {
+ while (data_cw > gm_data_codewords[5 * (layers - 1) + (ecc_level - 1)] && layers < 13) {
layers++;
}
/* ECC min level 1 for layers > 2 */
- while (data_cw > gm_data_codewords[(5 * (layers - 1)) + (ecc_level - 1)] && ecc_level > 1) {
+ while (data_cw > gm_data_codewords[5 * (layers - 1) + (ecc_level - 1)] && ecc_level > 1) {
ecc_level--;
}
}
diff --git a/backend/gs1.c b/backend/gs1.c
index 734b098a..9f117226 100644
--- a/backend/gs1.c
+++ b/backend/gs1.c
@@ -1767,8 +1767,8 @@ INTERNAL int zint_gs1_verify(struct zint_symbol *symbol, unsigned char source[],
data_location[i] = ai_location[i] + 3;
}
data_length[i] = 0;
- while ((data_location[i] + data_length[i] < length)
- && (source[data_location[i] + data_length[i]] != obracket)) {
+ while (data_location[i] + data_length[i] < length
+ && source[data_location[i] + data_length[i]] != obracket) {
data_length[i]++;
}
if (data_length[i] == 0) {
diff --git a/backend/hanxin.c b/backend/hanxin.c
index 0991c2ba..4e04fc87 100644
--- a/backend/hanxin.c
+++ b/backend/hanxin.c
@@ -108,7 +108,7 @@ static int hx_calc_binlen(const char mode[], const unsigned int ddata[], const i
}
/* GB 4-byte has indicator for each character (and no terminator) so not included here */
/* Region1/Region2 have special terminator to go directly into each other's mode so not included here */
- if (mode[i] != 'f' || ((mode[i] == '1' && lastmode == '2') || (mode[i] == '2' && lastmode == '1'))) {
+ if (mode[i] != 'f' || (mode[i] == '1' && lastmode == '2') || (mode[i] == '2' && lastmode == '1')) {
est_binlen += 4;
}
if (mode[i] == 'b') { /* Byte mode has byte count (and no terminator) */
@@ -177,17 +177,17 @@ static int hx_isRegion1(const unsigned int glyph) {
byte = glyph >> 8;
- if ((byte >= 0xb0) && (byte <= 0xd7)) {
- byte = glyph & 0xff;
- if ((byte >= 0xa1) && (byte <= 0xfe)) {
+ if (byte >= 0xB0 && byte <= 0xD7) {
+ byte = glyph & 0xFF;
+ if (byte >= 0xA1 && byte <= 0xFE) {
return 1;
}
- } else if ((byte >= 0xa1) && (byte <= 0xa3)) {
- byte = glyph & 0xff;
- if ((byte >= 0xa1) && (byte <= 0xfe)) {
+ } else if (byte >= 0xA1 && byte <= 0xA3) {
+ byte = glyph & 0xFF;
+ if (byte >= 0xA1 && byte <= 0xFE) {
return 1;
}
- } else if ((glyph >= 0xa8a1) && (glyph <= 0xa8c0)) {
+ } else if (glyph >= 0xA8A1 && glyph <= 0xA8C0) {
return 1;
}
@@ -199,9 +199,9 @@ static int hx_isRegion2(const unsigned int glyph) {
byte = glyph >> 8;
- if ((byte >= 0xd8) && (byte <= 0xf7)) {
- byte = glyph & 0xff;
- if ((byte >= 0xa1) && (byte <= 0xfe)) {
+ if (byte >= 0xD8 && byte <= 0xF7) {
+ byte = glyph & 0xFF;
+ if (byte >= 0xA1 && byte <= 0xFE) {
return 1;
}
}
@@ -214,12 +214,12 @@ static int hx_isDoubleByte(const unsigned int glyph) {
byte = glyph >> 8;
- if ((byte >= 0x81) && (byte <= 0xfe)) {
- byte = glyph & 0xff;
- if ((byte >= 0x40) && (byte <= 0x7e)) {
+ if (byte >= 0x81 && byte <= 0xFE) {
+ byte = glyph & 0xFF;
+ if (byte >= 0x40 && byte <= 0x7E) {
return 1;
}
- if ((byte >= 0x80) && (byte <= 0xfe)) {
+ if (byte >= 0x80 && byte <= 0xFE) {
return 1;
}
}
@@ -232,13 +232,13 @@ static int hx_isFourByte(const unsigned int glyph, const unsigned int glyph2) {
byte = glyph >> 8;
- if ((byte >= 0x81) && (byte <= 0xfe)) {
- byte = glyph & 0xff;
- if ((byte >= 0x30) && (byte <= 0x39)) {
+ if (byte >= 0x81 && byte <= 0xFE) {
+ byte = glyph & 0xFF;
+ if (byte >= 0x30 && byte <= 0x39) {
byte = glyph2 >> 8;
- if ((byte >= 0x81) && (byte <= 0xfe)) {
- byte = glyph2 & 0xff;
- if ((byte >= 0x30) && (byte <= 0x39)) {
+ if (byte >= 0x81 && byte <= 0xFE) {
+ byte = glyph2 & 0xFF;
+ if (byte >= 0x30 && byte <= 0x39) {
return 1;
}
}
@@ -273,19 +273,19 @@ static int hx_lookup_text2(const unsigned int input) {
return input;
}
- if ((input >= ' ') && (input <= '/')) {
+ if (input >= ' ' && input <= '/') {
return input - ' ' + 28;
}
- if ((input >= ':') && (input <= '@')) {
+ if (input >= ':' && input <= '@') {
return input - ':' + 44;
}
- if ((input >= '[') && (input <= 96)) {
+ if (input >= '[' && input <= 96) {
return input - '[' + 51;
}
- if ((input >= '{') && (input <= 127)) {
+ if (input >= '{' && input <= 127) {
return input - '{' + 57;
}
@@ -688,22 +688,22 @@ static void hx_calculate_binary(char binary[], const char mode[], const unsigned
i = 0;
while (i < block_length) {
- first_byte = (ddata[i + position] & 0xff00) >> 8;
- second_byte = ddata[i + position] & 0xff;
+ first_byte = (ddata[i + position] & 0xFF00) >> 8;
+ second_byte = ddata[i + position] & 0xFF;
/* Subset 1 */
- glyph = (0x5e * (first_byte - 0xb0)) + (second_byte - 0xa1);
+ glyph = (0x5E * (first_byte - 0xB0)) + (second_byte - 0xA1);
/* Subset 2 */
- if ((first_byte >= 0xa1) && (first_byte <= 0xa3)) {
- if ((second_byte >= 0xa1) && (second_byte <= 0xfe)) {
- glyph = (0x5e * (first_byte - 0xa1)) + (second_byte - 0xa1) + 0xeb0;
+ if (first_byte >= 0xA1 && first_byte <= 0xA3) {
+ if (second_byte >= 0xA1 && second_byte <= 0xFE) {
+ glyph = (0x5E * (first_byte - 0xA1)) + (second_byte - 0xA1) + 0xEB0;
}
}
/* Subset 3 */
- if ((ddata[i + position] >= 0xa8a1) && (ddata[i + position] <= 0xa8c0)) {
- glyph = (second_byte - 0xa1) + 0xfca;
+ if (ddata[i + position] >= 0xA8A1 && ddata[i + position] <= 0xA8C0) {
+ glyph = (second_byte - 0xA1) + 0xFCA;
}
if (debug_print) {
@@ -739,10 +739,10 @@ static void hx_calculate_binary(char binary[], const char mode[], const unsigned
i = 0;
while (i < block_length) {
- first_byte = (ddata[i + position] & 0xff00) >> 8;
- second_byte = ddata[i + position] & 0xff;
+ first_byte = (ddata[i + position] & 0xFF00) >> 8;
+ second_byte = ddata[i + position] & 0xFF;
- glyph = (0x5e * (first_byte - 0xd8)) + (second_byte - 0xa1);
+ glyph = (0x5E * (first_byte - 0xD8)) + (second_byte - 0xA1);
if (debug_print) {
printf(" %.3x[GB %.4x]", glyph, ddata[i + position]);
@@ -774,13 +774,13 @@ static void hx_calculate_binary(char binary[], const char mode[], const unsigned
i = 0;
while (i < block_length) {
- first_byte = (ddata[i + position] & 0xff00) >> 8;
- second_byte = ddata[i + position] & 0xff;
+ first_byte = (ddata[i + position] & 0xFF00) >> 8;
+ second_byte = ddata[i + position] & 0xFF;
- if (second_byte <= 0x7e) {
- glyph = (0xbe * (first_byte - 0x81)) + (second_byte - 0x40);
+ if (second_byte <= 0x7E) {
+ glyph = (0xBE * (first_byte - 0x81)) + (second_byte - 0x40);
} else {
- glyph = (0xbe * (first_byte - 0x81)) + (second_byte - 0x41);
+ glyph = (0xBE * (first_byte - 0x81)) + (second_byte - 0x41);
}
if (debug_print) {
@@ -813,13 +813,13 @@ static void hx_calculate_binary(char binary[], const char mode[], const unsigned
/* Mode indicator */
bp = z_bin_append_posn(7, 4, binary, bp);
- first_byte = (ddata[i + position] & 0xff00) >> 8;
- second_byte = ddata[i + position] & 0xff;
- third_byte = (ddata[i + position + 1] & 0xff00) >> 8;
- fourth_byte = ddata[i + position + 1] & 0xff;
+ first_byte = (ddata[i + position] & 0xFF00) >> 8;
+ second_byte = ddata[i + position] & 0xFF;
+ third_byte = (ddata[i + position + 1] & 0xFF00) >> 8;
+ fourth_byte = ddata[i + position + 1] & 0xFF;
- glyph = (0x3138 * (first_byte - 0x81)) + (0x04ec * (second_byte - 0x30)) +
- (0x0a * (third_byte - 0x81)) + (fourth_byte - 0x30);
+ glyph = (0x3138 * (first_byte - 0x81)) + (0x04EC * (second_byte - 0x30))
+ + (0x0A * (third_byte - 0x81)) + (fourth_byte - 0x30);
if (debug_print) {
printf(" %d", glyph);
@@ -916,8 +916,8 @@ static void hx_place_finder_bottom_right(unsigned char *grid, const int size) {
/* Avoid plotting outside symbol or over finder patterns */
static void hx_safe_plot(unsigned char *grid, const int size, const int x, const int y, const int value) {
- if ((x >= 0) && (x < size)) {
- if ((y >= 0) && (y < size)) {
+ if (x >= 0 && x < size) {
+ if (y >= 0 && y < size) {
if (grid[(y * size) + x] == 0) {
grid[(y * size) + x] = value;
}
@@ -1120,7 +1120,7 @@ static void hx_add_ecc(unsigned char fullstream[], const unsigned char datastrea
int i, j, block;
int input_position = 0;
int output_position = 0;
- const int table_d1_pos = ((version - 1) * 36) + ((ecc_level - 1) * 9);
+ const int table_d1_pos = (version - 1) * 36 + (ecc_level - 1) * 9;
rs_t rs;
zint_rs_init_gf(&rs, 0x163); /* x^8 + x^6 + x^5 + x + 1 = 0 */
@@ -1396,16 +1396,16 @@ static int hx_apply_bitmask(unsigned char *grid, const int size, const int versi
for (x = 0; x < size; x++) {
k = r + x;
- if (!(grid[k] & 0xf0)) {
+ if (!(grid[k] & 0xF0)) {
j = x + 1;
i = y + 1;
if (((i + j) & 1) == 0) {
mask[k] |= 0x02;
}
- if (((((i + j) % 3) + (j % 3)) & 1) == 0) {
+ if ((((i + j) % 3 + j % 3) & 1) == 0) {
mask[k] |= 0x04;
}
- if ((((i % j) + (j % i) + (i % 3) + (j % 3)) & 1) == 0) {
+ if (((i % j + j % i + i % 3 + j % 3) & 1) == 0) {
mask[k] |= 0x08;
}
}
@@ -1420,7 +1420,7 @@ static int hx_apply_bitmask(unsigned char *grid, const int size, const int versi
/* Do null pattern 00 separately first */
pattern = 0;
for (k = 0; k < size_squared; k++) {
- local[k] = grid[k] & 0x0f;
+ local[k] = grid[k] & 0x0F;
}
/* Set the Structural Info */
hx_set_function_info(local, size, version, ecc_level, pattern, 0 /*debug_print*/);
@@ -1435,7 +1435,7 @@ static int hx_apply_bitmask(unsigned char *grid, const int size, const int versi
if (mask[k] & bit) {
local[k] = grid[k] ^ 0x01;
} else {
- local[k] = grid[k] & 0x0f;
+ local[k] = grid[k] & 0x0F;
}
}
/* Set the Structural Info */
@@ -1560,7 +1560,7 @@ INTERNAL int zint_hanxin(struct zint_symbol *symbol, struct zint_seg segs[], con
binary = (char *) malloc(est_binlen + 1);
- if ((ecc_level <= 0) || (ecc_level >= 5)) {
+ if (ecc_level <= 0 || ecc_level >= 5) {
ecc_level = 1;
}
@@ -1587,7 +1587,7 @@ INTERNAL int zint_hanxin(struct zint_symbol *symbol, struct zint_seg segs[], con
codewords);
}
- if ((symbol->option_2 < 0) || (symbol->option_2 > 84)) {
+ if (symbol->option_2 < 0 || symbol->option_2 > 84) {
symbol->option_2 = 0;
}
@@ -1595,7 +1595,7 @@ INTERNAL int zint_hanxin(struct zint_symbol *symbol, struct zint_seg segs[], con
version = symbol->option_2;
}
- if ((symbol->option_2 != 0) && (symbol->option_2 < version)) {
+ if (symbol->option_2 != 0 && symbol->option_2 < version) {
free(binary);
if (ecc_level == 1) {
return ZEXT z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 542,
diff --git a/backend/imail.c b/backend/imail.c
index 61df7596..a2eac9b7 100644
--- a/backend/imail.c
+++ b/backend/imail.c
@@ -418,11 +418,11 @@ INTERNAL int zint_usps_imail(struct zint_symbol *symbol, unsigned char source[],
/* Translate 4-state data pattern to symbol */
read = 0;
for (i = 0; i < 65; i++) {
- if ((data_pattern[i] == '1') || (data_pattern[i] == '0')) {
+ if (data_pattern[i] == '1' || data_pattern[i] == '0') {
z_set_module(symbol, 0, read);
}
z_set_module(symbol, 1, read);
- if ((data_pattern[i] == '2') || (data_pattern[i] == '0')) {
+ if (data_pattern[i] == '2' || data_pattern[i] == '0') {
z_set_module(symbol, 2, read);
}
read += 2;
diff --git a/backend/library.c b/backend/library.c
index fbcfc3b7..2b68ed8b 100644
--- a/backend/library.c
+++ b/backend/library.c
@@ -37,6 +37,7 @@
#include
#include "common.h"
#include "eci.h"
+#include "filemem.h"
#include "gs1.h"
#include "output.h"
#include "zfiletypes.h"
@@ -127,8 +128,6 @@ void ZBarcode_Clear(struct zint_symbol *symbol) {
symbol->memfile_size = 0;
z_rt_free_segs(symbol);
-
- /* If there is a rendered version, ensure its memory is released */
zint_vector_free(symbol);
}
@@ -286,77 +285,59 @@ INTERNAL int zint_test_error_tag(int error_number, struct zint_symbol *symbol, c
}
#endif
-/* Output a hexadecimal representation of the rendered symbol */
-static int dump_plot(struct zint_symbol *symbol) {
- FILE *f;
- int i, r;
- static const char hex[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
- int space = 0;
- const int output_to_stdout = symbol->output_options & BARCODE_STDOUT;
+/* Output a hexadecimal representation of the rendered symbol (TXT files - includes frontend "--dump" option) */
+static int txt_hex_plot(struct zint_symbol *symbol) {
+ static const char hex[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
+ struct filemem fm;
+ struct filemem *const fmp = &fm;
+ int r;
- if (output_to_stdout) {
- f = stdout;
- } else {
-#ifdef _WIN32
- f = zint_out_win_fopen(symbol->outfile, "w");
-#else
- f = fopen(symbol->outfile, "w");
-#endif
- if (!f) {
- return z_errtxt(ZINT_ERROR_FILE_ACCESS, symbol, 201, "Could not open output file");
- }
+ if (!zint_fm_open(fmp, symbol, "w")) {
+ return ZEXT z_errtxtf(ZINT_ERROR_FILE_ACCESS, symbol, 201, "Could not open TXT output file (%1$d: %2$s)",
+ fmp->err, strerror(fmp->err));
}
for (r = 0; r < symbol->rows; r++) {
- int byt = 0;
+ int space = 0, byt = 0;
+ int i;
for (i = 0; i < symbol->width; i++) {
- byt = byt << 1;
+ byt <<= 1;
if (symbol->symbology == BARCODE_ULTRA) {
if (z_module_colour_is_set(symbol, r, i)) {
- byt += 1;
+ byt++;
}
} else {
if (z_module_is_set(symbol, r, i)) {
- byt += 1;
+ byt++;
}
}
- if ((i + 1) % 4 == 0) {
- fputc(hex[byt], f);
+ if (((i + 1) & 0x3) == 0) {
+ zint_fm_putc(hex[byt], fmp);
space++;
byt = 0;
}
if (space == 2 && i + 1 < symbol->width) {
- fputc(' ', f);
+ zint_fm_putc(' ', fmp);
space = 0;
}
}
- if (symbol->width % 4 != 0) {
- byt = byt << (4 - (symbol->width % 4));
- fputc(hex[byt], f);
+ if (symbol->width & 0x03) {
+ byt <<= 4 - (symbol->width & 0x03);
+ zint_fm_putc(hex[byt], fmp);
}
- fputc('\n', f);
- space = 0;
+ zint_fm_putc('\n', fmp);
}
- if (ferror(f)) {
- ZEXT z_errtxtf(0, symbol, 795, "Incomplete write to output (%1$d: %2$s)", errno, strerror(errno));
- if (!output_to_stdout) {
- (void) fclose(f);
- }
+ if (zint_fm_error(fmp)) {
+ ZEXT z_errtxtf(0, symbol, 795, "Incomplete write of TXT output (%1$d: %2$s)", fmp->err, strerror(fmp->err));
+ (void) zint_fm_close(fmp, symbol);
return ZINT_ERROR_FILE_WRITE;
}
- if (output_to_stdout) {
- if (fflush(f) != 0) {
- return ZEXT z_errtxtf(ZINT_ERROR_FILE_WRITE, symbol, 796, "Incomplete flush to output (%1$d: %2$s)",
- errno, strerror(errno));
- }
- } else {
- if (fclose(f) != 0) {
- return ZEXT z_errtxtf(ZINT_ERROR_FILE_WRITE, symbol, 792, "Failure on closing output file (%1$d: %2$s)",
- errno, strerror(errno));
- }
+ if (!zint_fm_close(fmp, symbol)) {
+ return ZEXT z_errtxtf(ZINT_ERROR_FILE_WRITE, symbol, 792, "Failure on closing TXT output file (%1$d: %2$s)",
+ fmp->err, strerror(fmp->err));
}
return 0;
@@ -698,7 +679,7 @@ static void strip_bom(unsigned char *source, int *input_length) {
int i;
/* Note if BOM is only data then not stripped */
- if (*input_length > 3 && (source[0] == 0xef) && (source[1] == 0xbb) && (source[2] == 0xbf)) {
+ if (*input_length > 3 && source[0] == 0xEF && source[1] == 0xBB && source[2] == 0xBF) {
/* BOM at start of input data, strip in accordance with RFC 3629 */
for (i = 3; i <= *input_length; i++) { /* Include terminating NUL */
source[i - 3] = source[i];
@@ -862,7 +843,7 @@ static int escape_char_process(struct zint_symbol *symbol, const unsigned char *
}
}
/* Exclude reversed BOM and surrogates and out-of-range */
- if (unicode == 0xfffe || (unicode >= 0xd800 && unicode < 0xe000) || unicode > 0x10ffff) {
+ if (unicode == 0xFFFE || (unicode >= 0xD800 && unicode < 0xE000) || unicode > 0x10FFFF) {
return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 246,
"Value of escape sequence '%.*s' in input out of range",
ch == 'u' ? 6 : 8, input_string + in_posn);
@@ -1266,7 +1247,7 @@ int ZBarcode_Encode_Segs(struct zint_symbol *symbol, const struct zint_seg segs[
error_number = extended_or_reduced_charset(symbol, local_segs, seg_count);
- if ((error_number == ZINT_ERROR_INVALID_DATA) && have_zero_eci && supports_eci(symbol->symbology)
+ if (error_number == ZINT_ERROR_INVALID_DATA && have_zero_eci && supports_eci(symbol->symbology)
&& (symbol->input_mode & 0x07) == UNICODE_MODE) {
/* Try another ECI mode */
const int first_eci_set = zint_get_best_eci_segs(symbol, local_segs, seg_count);
@@ -1369,7 +1350,7 @@ int ZBarcode_Print(struct zint_symbol *symbol, int rotate_angle) {
error_number = zint_plot_vector(symbol, rotate_angle, filetypes[i].filetype);
}
} else {
- error_number = dump_plot(symbol);
+ error_number = txt_hex_plot(symbol);
}
} else {
return error_tag(ZINT_ERROR_INVALID_OPTION, symbol, 225, "Unknown output format");
@@ -1573,7 +1554,7 @@ int ZBarcode_Encode_File(struct zint_symbol *symbol, const char *filename) {
return error_tag(ZINT_ERROR_INVALID_DATA, symbol, -1, NULL);
}
nRead += n;
- } while (!feof(file) && (0 < n) && ((long) nRead < fileLen));
+ } while (!feof(file) && n > 0 && (long) nRead < fileLen);
if (file_opened) {
if (fclose(file) != 0) {
diff --git a/backend/mailmark.c b/backend/mailmark.c
index 605244b1..6ddeb685 100644
--- a/backend/mailmark.c
+++ b/backend/mailmark.c
@@ -206,7 +206,7 @@ INTERNAL int zint_mailmark_4s(struct zint_symbol *symbol, unsigned char source[]
}
memset(local_source + length, ' ', 22 - length);
length = 22;
- } else if ((length > 22) && (length < 26)) {
+ } else if (length > 22 && length < 26) {
memset(local_source + length, ' ', 26 - length);
length = 26;
}
@@ -224,19 +224,19 @@ INTERNAL int zint_mailmark_4s(struct zint_symbol *symbol, unsigned char source[]
/* Format is in the range 0-4 */
format = z_ctoi(local_source[0]);
- if ((format < 0) || (format > 4)) {
+ if (format < 0 || format > 4) {
return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 582, "Format (1st character) out of range (0 to 4)");
}
/* Version ID is in the range 1-4 */
version_id = z_ctoi(local_source[1]) - 1;
- if ((version_id < 0) || (version_id > 3)) {
+ if (version_id < 0 || version_id > 3) {
return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 583, "Version ID (2nd character) out of range (1 to 4)");
}
/* Class is in the range 0-9,A-E */
mail_class = z_ctoi(local_source[2]);
- if ((mail_class < 0) || (mail_class > 14)) {
+ if (mail_class < 0 || mail_class > 14) {
return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 584,
"Class (3rd character) out of range (0 to 9 and A to E)");
}
@@ -468,11 +468,11 @@ INTERNAL int zint_mailmark_4s(struct zint_symbol *symbol, unsigned char source[]
/* Translate 4-state data pattern to symbol */
j = 0;
for (i = 0, len = d - bar; i < len; i++) {
- if ((bar[i] == 'F') || (bar[i] == 'A')) {
+ if (bar[i] == 'F' || bar[i] == 'A') {
z_set_module(symbol, 0, j);
}
z_set_module(symbol, 1, j);
- if ((bar[i] == 'F') || (bar[i] == 'D')) {
+ if (bar[i] == 'F' || bar[i] == 'D') {
z_set_module(symbol, 2, j);
}
j += 2;
diff --git a/backend/medical.c b/backend/medical.c
index 569d4ab0..4149f277 100644
--- a/backend/medical.c
+++ b/backend/medical.c
@@ -69,7 +69,7 @@ INTERNAL int zint_pharma(struct zint_symbol *symbol, unsigned char source[], int
}
tester = z_to_int(source, length);
- if ((tester < 3) || (tester > 131070)) {
+ if (tester < 3 || tester > 131070) {
return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 352, "Input value '%d' out of range (3 to 131070)", tester);
}
@@ -162,7 +162,7 @@ INTERNAL int zint_pharma_two(struct zint_symbol *symbol, unsigned char source[],
}
tester = z_to_int(source, length);
- if ((tester < 4) || (tester > 64570080)) {
+ if (tester < 4 || tester > 64570080) {
return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 353, "Input value '%d' out of range (4 to 64570080)",
tester);
}
@@ -170,10 +170,10 @@ INTERNAL int zint_pharma_two(struct zint_symbol *symbol, unsigned char source[],
writer = 0;
for (loopey = 0; loopey < h; loopey++) {
- if ((height_pattern[loopey] == '2') || (height_pattern[loopey] == '3')) {
+ if (height_pattern[loopey] == '2' || height_pattern[loopey] == '3') {
z_set_module(symbol, 0, writer);
}
- if ((height_pattern[loopey] == '1') || (height_pattern[loopey] == '3')) {
+ if (height_pattern[loopey] == '1' || height_pattern[loopey] == '3') {
z_set_module(symbol, 1, writer);
}
writer += 2;
diff --git a/backend/output.c b/backend/output.c
index 9bb7ffcf..fddd281d 100644
--- a/backend/output.c
+++ b/backend/output.c
@@ -194,13 +194,13 @@ INTERNAL int zint_out_colour_char_to_rgb(const unsigned char ch, unsigned char *
unsigned char *blue) {
static const char chars[] = "WCBMRYGK";
static const unsigned char colours[8][3] = {
- { 0xff, 0xff, 0xff, }, /* White */
- { 0, 0xff, 0xff, }, /* Cyan */
- { 0, 0, 0xff, }, /* Blue */
- { 0xff, 0, 0xff, }, /* Magenta */
- { 0xff, 0, 0, }, /* Red */
- { 0xff, 0xff, 0, }, /* Yellow */
- { 0, 0xff, 0, }, /* Green */
+ { 0xFF, 0xFF, 0xFF, }, /* White */
+ { 0, 0xFF, 0xFF, }, /* Cyan */
+ { 0, 0, 0xFF, }, /* Blue */
+ { 0xFF, 0, 0xFF, }, /* Magenta */
+ { 0xFF, 0, 0, }, /* Red */
+ { 0xFF, 0xFF, 0, }, /* Yellow */
+ { 0, 0xFF, 0, }, /* Green */
{ 0, 0, 0, }, /* Black */
};
int i = z_posn(chars, (const char) ch);
@@ -801,12 +801,12 @@ INTERNAL int zint_out_process_upcean(const struct zint_symbol *symbol, const int
upceanflag = 8;
break;
}
- } else if ((symbol->symbology == BARCODE_UPCA) || (symbol->symbology == BARCODE_UPCA_CHK)
- || (symbol->symbology == BARCODE_UPCA_CC)) {
+ } else if (symbol->symbology == BARCODE_UPCA || symbol->symbology == BARCODE_UPCA_CHK
+ || symbol->symbology == BARCODE_UPCA_CC) {
main_width = 95 + comp_xoffset; /* UPC-A main symbol 95 modules wide */
upceanflag = 12;
- } else if ((symbol->symbology == BARCODE_UPCE) || (symbol->symbology == BARCODE_UPCE_CHK)
- || (symbol->symbology == BARCODE_UPCE_CC)) {
+ } else if (symbol->symbology == BARCODE_UPCE || symbol->symbology == BARCODE_UPCE_CHK
+ || symbol->symbology == BARCODE_UPCE_CC) {
main_width = 51 + comp_xoffset; /* UPC-E main symbol 51 modules wide */
upceanflag = 6;
}
diff --git a/backend/pcx.c b/backend/pcx.c
index 357f1633..79e0921e 100644
--- a/backend/pcx.c
+++ b/backend/pcx.c
@@ -129,11 +129,11 @@ INTERNAL int zint_pcx_pixel_plot(struct zint_symbol *symbol, const unsigned char
previous = rle_row[0];
run_count = 1;
for (column = 1; column < bytes_per_line; column++) { /* Note going up to bytes_per_line */
- if ((previous == rle_row[column]) && (run_count < 63)) {
+ if (previous == rle_row[column] && run_count < 63) {
run_count++;
} else {
- if (run_count > 1 || (previous & 0xc0) == 0xc0) {
- run_count += 0xc0;
+ if (run_count > 1 || (previous & 0xC0) == 0xC0) {
+ run_count += 0xC0;
zint_fm_putc(run_count, fmp);
}
zint_fm_putc(previous, fmp);
@@ -142,8 +142,8 @@ INTERNAL int zint_pcx_pixel_plot(struct zint_symbol *symbol, const unsigned char
}
}
- if (run_count > 1 || (previous & 0xc0) == 0xc0) {
- run_count += 0xc0;
+ if (run_count > 1 || (previous & 0xC0) == 0xC0) {
+ run_count += 0xC0;
zint_fm_putc(run_count, fmp);
}
zint_fm_putc(previous, fmp);
diff --git a/backend/pdf417.c b/backend/pdf417.c
index 11512c3d..ceb11c60 100644
--- a/backend/pdf417.c
+++ b/backend/pdf417.c
@@ -265,9 +265,9 @@ static int pdf_text_submode_length(const unsigned char chaine[], const int start
} else {
/* Obliged to change table */
int newtable;
- if (j == (length - 1) || !(listet[j] & listet[j + 1])) {
+ if (j == length - 1 || !(listet[j] & listet[j + 1])) {
/* We change only one character - look for temporary switch */
- if ((listet[j] & T_ALPHA) && (curtable == T_LOWER)) {
+ if ((listet[j] & T_ALPHA) && curtable == T_LOWER) {
wnet += 2; /* AS+char */
continue;
}
@@ -341,16 +341,16 @@ static void pdf_appendix_d_encode(const unsigned char *chaine, short liste[3][PD
while (i < indexliste) {
- if ((liste[1][i] == PDF_NUM) && pdf_num_stay(chaine, indexliste, liste, i)) {
+ if (liste[1][i] == PDF_NUM && pdf_num_stay(chaine, indexliste, liste, i)) {
/* Leave as numeric */
liste[0][last] = liste[0][i];
liste[1][last] = PDF_NUM;
liste[2][last] = liste[2][i];
stayintext = 0;
last++;
- } else if (((liste[1][i] == PDF_TEX) || (liste[1][i] == PDF_NUM))
- && (stayintext || i == indexliste - 1 || (liste[0][i] >= 5)
- || (pdf_text_num_length(liste, indexliste, i) >= 5))) {
+ } else if ((liste[1][i] == PDF_TEX || liste[1][i] == PDF_NUM)
+ && (stayintext || i == indexliste - 1 || liste[0][i] >= 5
+ || pdf_text_num_length(liste, indexliste, i) >= 5)) {
/* Set to text and combine additional text/short numeric segments */
liste[0][last] = liste[0][i];
liste[1][last] = PDF_TEX;
@@ -359,7 +359,7 @@ static void pdf_appendix_d_encode(const unsigned char *chaine, short liste[3][PD
next = i + 1;
while (next < indexliste) {
- if ((liste[1][next] == PDF_NUM) && pdf_num_stay(chaine, indexliste, liste, next)) {
+ if (liste[1][next] == PDF_NUM && pdf_num_stay(chaine, indexliste, liste, next)) {
break;
} else if (liste[1][next] == PDF_BYT) {
break;
@@ -383,12 +383,12 @@ static void pdf_appendix_d_encode(const unsigned char *chaine, short liste[3][PD
while (next < indexliste) {
if (liste[1][next] != PDF_BYT) {
/* Check for case of a single byte shift from text mode */
- if ((liste[0][last] == 1) && (last > 0) && (liste[1][last - 1] == PDF_TEX)) {
+ if (liste[0][last] == 1 && last > 0 && liste[1][last - 1] == PDF_TEX) {
stayintext = 1;
break;
}
- if ((liste[0][next] >= 5) || (pdf_text_num_length(liste, indexliste, next) >= 5)) {
+ if (liste[0][next] >= 5 || pdf_text_num_length(liste, indexliste, next) >= 5) {
break;
}
}
@@ -465,9 +465,9 @@ static void pdf_textprocess(short *chainemc, int *p_mclength, const unsigned cha
} else {
/* Obliged to change table */
int newtable;
- if (j == (length - 1) || !(listet[0][j] & listet[0][j + 1])) {
+ if (j == length - 1 || !(listet[0][j] & listet[0][j + 1])) {
/* We change only one character - look for temporary switch */
- if ((listet[0][j] & T_ALPHA) && (curtable == T_LOWER)) {
+ if ((listet[0][j] & T_ALPHA) && curtable == T_LOWER) {
chainet[wnet++] = 27; /* AS */
chainet[wnet++] = listet[1][j];
continue;
@@ -1021,7 +1021,7 @@ static int pdf_initial(struct zint_symbol *symbol, const unsigned char chaine[],
do {
liste[1][indexliste] = mode;
liste[2][indexliste] = indexchaine;
- while ((liste[1][indexliste] == mode) && (indexchaine < length)) {
+ while (liste[1][indexliste] == mode && indexchaine < length) {
liste[0][indexliste]++;
indexchaine++;
mode = pdf_quelmode(chaine[indexchaine]);
@@ -1469,7 +1469,7 @@ INTERNAL int zint_pdf417(struct zint_symbol *symbol, struct zint_seg segs[], con
error_number = 0;
- if ((symbol->option_1 < -1) || (symbol->option_1 > 8)) {
+ if (symbol->option_1 < -1 || symbol->option_1 > 8) {
z_errtxtf(0, symbol, 460, "Error correction level '%d' out of range (0 to 8)", symbol->option_1);
if (symbol->warn_level == WARN_FAIL_ALL) {
return ZINT_ERROR_INVALID_OPTION;
@@ -1477,7 +1477,7 @@ INTERNAL int zint_pdf417(struct zint_symbol *symbol, struct zint_seg segs[], con
error_number = z_errtxt_adj(ZINT_WARN_INVALID_OPTION, symbol, "%1$s%2$s", ", ignoring");
symbol->option_1 = -1;
}
- if ((symbol->option_2 < 0) || (symbol->option_2 > 30)) {
+ if (symbol->option_2 < 0 || symbol->option_2 > 30) {
z_errtxtf(0, symbol, 461, "Number of columns '%d' out of range (1 to 30)", symbol->option_2);
if (symbol->warn_level == WARN_FAIL_ALL) {
return ZINT_ERROR_INVALID_OPTION;
diff --git a/backend/plessey.c b/backend/plessey.c
index 69f3755c..0d4023be 100644
--- a/backend/plessey.c
+++ b/backend/plessey.c
@@ -346,7 +346,7 @@ INTERNAL int zint_msi_plessey(struct zint_symbol *symbol, unsigned char source[]
check_option -= 10;
no_checktext = 1;
}
- if ((check_option < 0) || (check_option > 6)) {
+ if (check_option < 0 || check_option > 6) {
check_option = 0;
}
diff --git a/backend/postal.c b/backend/postal.c
index 238608de..e9c534c3 100644
--- a/backend/postal.c
+++ b/backend/postal.c
@@ -492,11 +492,11 @@ INTERNAL int zint_rm4scc(struct zint_symbol *symbol, unsigned char source[], int
writer = 0;
h = (int) strlen(height_pattern);
for (loopey = 0; loopey < h; loopey++) {
- if ((height_pattern[loopey] == '1') || (height_pattern[loopey] == '0')) {
+ if (height_pattern[loopey] == '1' || height_pattern[loopey] == '0') {
z_set_module(symbol, 0, writer);
}
z_set_module(symbol, 1, writer);
- if ((height_pattern[loopey] == '2') || (height_pattern[loopey] == '0')) {
+ if (height_pattern[loopey] == '2' || height_pattern[loopey] == '0') {
z_set_module(symbol, 2, writer);
}
writer += 2;
@@ -559,11 +559,11 @@ INTERNAL int zint_kix(struct zint_symbol *symbol, unsigned char source[], int le
writer = 0;
h = d - height_pattern;
for (loopey = 0; loopey < h; loopey++) {
- if ((height_pattern[loopey] == '1') || (height_pattern[loopey] == '0')) {
+ if (height_pattern[loopey] == '1' || height_pattern[loopey] == '0') {
z_set_module(symbol, 0, writer);
}
z_set_module(symbol, 1, writer);
- if ((height_pattern[loopey] == '2') || (height_pattern[loopey] == '0')) {
+ if (height_pattern[loopey] == '2' || height_pattern[loopey] == '0') {
z_set_module(symbol, 2, writer);
}
writer += 2;
@@ -612,11 +612,11 @@ INTERNAL int zint_daft(struct zint_symbol *symbol, unsigned char source[], int l
writer = 0;
for (loopey = 0; loopey < length; loopey++) {
- if ((posns[loopey] == 1) || (posns[loopey] == 0)) {
+ if (posns[loopey] == 1 || posns[loopey] == 0) {
z_set_module(symbol, 0, writer);
}
z_set_module(symbol, 1, writer);
- if ((posns[loopey] == 2) || (posns[loopey] == 0)) {
+ if (posns[loopey] == 2 || posns[loopey] == 0) {
z_set_module(symbol, 2, writer);
}
writer += 2;
@@ -705,7 +705,7 @@ INTERNAL int zint_japanpost(struct zint_symbol *symbol, unsigned char source[],
i = 0;
inter_posn = 0;
do {
- if (z_isdigit(source[i]) || (source[i] == '-')) {
+ if (z_isdigit(source[i]) || source[i] == '-') {
inter[inter_posn] = source[i];
inter_posn++;
} else {
@@ -722,7 +722,7 @@ INTERNAL int zint_japanpost(struct zint_symbol *symbol, unsigned char source[],
inter_posn += 2;
}
i++;
- } while ((i < length) && (inter_posn < 20));
+ } while (i < length && inter_posn < 20);
if (i != length || inter[20] != '\0') {
return z_errtxt(ZINT_ERROR_TOO_LONG, symbol, 477,
@@ -762,11 +762,11 @@ INTERNAL int zint_japanpost(struct zint_symbol *symbol, unsigned char source[],
writer = 0;
h = d - pattern;
for (loopey = 0; loopey < h; loopey++) {
- if ((pattern[loopey] == '2') || (pattern[loopey] == '1')) {
+ if (pattern[loopey] == '2' || pattern[loopey] == '1') {
z_set_module(symbol, 0, writer);
}
z_set_module(symbol, 1, writer);
- if ((pattern[loopey] == '3') || (pattern[loopey] == '1')) {
+ if (pattern[loopey] == '3' || pattern[loopey] == '1') {
z_set_module(symbol, 2, writer);
}
writer += 2;
diff --git a/backend/qr.c b/backend/qr.c
index 51301bf2..ecd553e0 100644
--- a/backend/qr.c
+++ b/backend/qr.c
@@ -438,45 +438,44 @@ static int qr_binary(char binary[], int bp, const int version, const char mode[]
modebits = qr_mode_bits(version);
do {
- char data_block = mode[position];
- int short_data_block_length = 0;
+ const char block_mode = mode[position];
+ int block_length = 0;
int double_byte = 0;
do {
- if (data_block == 'B' && ddata[position + short_data_block_length] > 0xFF) {
+ if (block_mode == 'B' && ddata[position + block_length] > 0xFF) {
double_byte++;
}
- short_data_block_length++;
- } while (((short_data_block_length + position) < length)
- && (mode[position + short_data_block_length] == data_block));
+ block_length++;
+ } while (position + block_length < length && mode[position + block_length] == block_mode);
/* Mode indicator */
if (modebits) {
- bp = z_bin_append_posn(qr_mode_indicator(version, data_block), modebits, binary, bp);
+ bp = z_bin_append_posn(qr_mode_indicator(version, block_mode), modebits, binary, bp);
}
- switch (data_block) {
+ switch (block_mode) {
case 'K':
/* Kanji mode */
/* Character count indicator */
- bp = z_bin_append_posn(short_data_block_length, qr_cci_bits(version, data_block), binary, bp);
+ bp = z_bin_append_posn(block_length, qr_cci_bits(version, block_mode), binary, bp);
if (debug_print) {
- printf("Kanji block (length %d)\n\t", short_data_block_length);
+ printf("Kanji block (length %d)\n\t", block_length);
}
/* Character representation */
- for (i = 0; i < short_data_block_length; i++) {
+ for (i = 0; i < block_length; i++) {
unsigned int jis = ddata[position + i];
int prod;
- if (jis >= 0x8140 && jis <= 0x9ffc)
+ if (jis >= 0x8140 && jis <= 0x9FFC)
jis -= 0x8140;
- else if (jis >= 0xe040 && jis <= 0xebbf)
- jis -= 0xc140;
+ else if (jis >= 0xE040 && jis <= 0xEBBF)
+ jis -= 0xC140;
- prod = ((jis >> 8) * 0xc0) + (jis & 0xff);
+ prod = ((jis >> 8) * 0xC0) + (jis & 0xFF);
bp = z_bin_append_posn(prod, 13, binary, bp);
@@ -494,15 +493,14 @@ static int qr_binary(char binary[], int bp, const int version, const char mode[]
/* Byte mode */
/* Character count indicator */
- bp = z_bin_append_posn(short_data_block_length + double_byte, qr_cci_bits(version, data_block),
- binary, bp);
+ bp = z_bin_append_posn(block_length + double_byte, qr_cci_bits(version, block_mode), binary, bp);
if (debug_print) {
- printf("Byte block (length %d)\n\t", short_data_block_length + double_byte);
+ printf("Byte block (length %d)\n\t", block_length + double_byte);
}
/* Character representation */
- for (i = 0; i < short_data_block_length; i++) {
+ for (i = 0; i < block_length; i++) {
unsigned int byte = ddata[position + i];
bp = z_bin_append_posn(byte, byte > 0xFF ? 16 : 8, binary, bp);
@@ -522,7 +520,7 @@ static int qr_binary(char binary[], int bp, const int version, const char mode[]
percent_count = 0;
if (gs1) {
- for (i = 0; i < short_data_block_length; i++) {
+ for (i = 0; i < block_length; i++) {
if (ddata[position + i] == '%') {
percent_count++;
}
@@ -530,21 +528,20 @@ static int qr_binary(char binary[], int bp, const int version, const char mode[]
}
/* Character count indicator */
- bp = z_bin_append_posn(short_data_block_length + percent_count, qr_cci_bits(version, data_block),
- binary, bp);
+ bp = z_bin_append_posn(block_length + percent_count, qr_cci_bits(version, block_mode), binary, bp);
if (debug_print) {
- printf("Alpha block (length %d)\n\t", short_data_block_length + percent_count);
+ printf("Alpha block (length %d)\n\t", block_length + percent_count);
}
/* Character representation */
i = 0;
- while (i < short_data_block_length) {
+ while (i < block_length) {
int count;
int first = 0, second = 0, prod;
if (percent == 0) {
- if (gs1 && (ddata[position + i] == '%')) {
+ if (gs1 && ddata[position + i] == '%') {
first = QR_PERCENT;
second = QR_PERCENT;
count = 2;
@@ -560,8 +557,8 @@ static int qr_binary(char binary[], int bp, const int version, const char mode[]
i++;
prod = first;
- if (i < short_data_block_length && mode[position + i] == 'A') {
- if (gs1 && (ddata[position + i] == '%')) {
+ if (i < block_length && mode[position + i] == 'A') {
+ if (gs1 && ddata[position + i] == '%') {
second = QR_PERCENT;
count = 2;
prod = (first * 45) + second;
@@ -585,8 +582,8 @@ static int qr_binary(char binary[], int bp, const int version, const char mode[]
prod = first;
percent = 0;
- if (i < short_data_block_length && mode[position + i] == 'A') {
- if (gs1 && (ddata[position + i] == '%')) {
+ if (i < block_length && mode[position + i] == 'A') {
+ if (gs1 && ddata[position + i] == '%') {
second = QR_PERCENT;
count = 2;
prod = (first * 45) + second;
@@ -620,15 +617,15 @@ static int qr_binary(char binary[], int bp, const int version, const char mode[]
/* Numeric mode */
/* Character count indicator */
- bp = z_bin_append_posn(short_data_block_length, qr_cci_bits(version, data_block), binary, bp);
+ bp = z_bin_append_posn(block_length, qr_cci_bits(version, block_mode), binary, bp);
if (debug_print) {
- printf("Number block (length %d)\n\t", short_data_block_length);
+ printf("Number block (length %d)\n\t", block_length);
}
/* Character representation */
i = 0;
- while (i < short_data_block_length) {
+ while (i < block_length) {
int count;
int first = 0, prod;
@@ -636,12 +633,12 @@ static int qr_binary(char binary[], int bp, const int version, const char mode[]
count = 1;
prod = first;
- if (i + 1 < short_data_block_length && mode[position + i + 1] == 'N') {
+ if (i + 1 < block_length && mode[position + i + 1] == 'N') {
int second = z_ctoi((const char) ddata[position + i + 1]);
count = 2;
prod = (prod * 10) + second;
- if (i + 2 < short_data_block_length && mode[position + i + 2] == 'N') {
+ if (i + 2 < block_length && mode[position + i + 2] == 'N') {
int third = z_ctoi((const char) ddata[position + i + 2]);
count = 3;
prod = (prod * 10) + third;
@@ -664,7 +661,7 @@ static int qr_binary(char binary[], int bp, const int version, const char mode[]
break;
}
- position += short_data_block_length;
+ position += block_length;
} while (position < length);
return bp;
@@ -683,6 +680,8 @@ static int qr_binary_segs(unsigned char datastream[], const int version, const i
int toggle;
char *binary = (char *) z_alloca(est_binlen + 12);
+ assert(seg_count > 0); /* Suppress clang-tidy clang-analyzer-core.uninitialized.Assign warning */
+
*binary = '\0';
if (p_structapp) {
@@ -753,7 +752,7 @@ static int qr_binary_segs(unsigned char datastream[], const int version, const i
toggle = 0;
for (i = current_bytes; i < target_codewords; i++) {
if (toggle == 0) {
- datastream[i] = 0xec;
+ datastream[i] = 0xEC;
toggle = 1;
} else {
datastream[i] = 0x11;
@@ -777,7 +776,6 @@ static void qr_add_ecc(unsigned char fullstream[], const unsigned char datastrea
const int data_cw, const int blocks, const int debug_print) {
int ecc_cw;
int short_data_block_length;
- int qty_long_blocks;
int qty_short_blocks;
int ecc_block_length;
int i, j, length_this_block, in_posn;
@@ -797,13 +795,14 @@ static void qr_add_ecc(unsigned char fullstream[], const unsigned char datastrea
assert(blocks > 0);
short_data_block_length = data_cw / blocks;
- qty_long_blocks = data_cw % blocks;
- qty_short_blocks = blocks - qty_long_blocks;
+ qty_short_blocks = blocks - data_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(qty_long_blocks || qty_short_blocks);
+ assert(data_cw > 0);
+ assert(short_data_block_length >= 1 && short_data_block_length <= 122);
+ assert(qty_short_blocks > 0);
+ assert(ecc_block_length > 0);
data_block = (unsigned char *) z_alloca(short_data_block_length + 1);
ecc_block = (unsigned char *) z_alloca(ecc_block_length);
@@ -816,15 +815,10 @@ static void qr_add_ecc(unsigned char fullstream[], const unsigned char datastrea
in_posn = 0;
for (i = 0; i < blocks; i++) {
- if (i < qty_short_blocks) {
- length_this_block = short_data_block_length;
- } else {
- length_this_block = short_data_block_length + 1;
- }
+ length_this_block = short_data_block_length + (i >= qty_short_blocks);
for (j = 0; j < length_this_block; j++) {
- /* This false-positive popped up with clang-tidy 14.0.1 */
- data_block[j] = datastream[in_posn + j]; /* NOLINT(clang-analyzer-core.uninitialized.Assign) */
+ data_block[j] = datastream[in_posn + j];
}
zint_rs_encode(&rs, length_this_block, data_block, ecc_block);
@@ -845,8 +839,7 @@ static void qr_add_ecc(unsigned char fullstream[], const unsigned char datastrea
}
for (j = 0; j < short_data_block_length; j++) {
- /* And another with clang-tidy 14.0.6 */
- interleaved_data[(j * blocks) + i] = data_block[j]; /* NOLINT(clang-analyzer-core.uninitialized.Assign) */
+ interleaved_data[(j * blocks) + i] = data_block[j];
}
if (i >= qty_short_blocks) {
@@ -883,11 +876,7 @@ static void qr_place_finder(unsigned char grid[], const int size, const int x, c
for (xp = 0; xp < 7; xp++) {
for (yp = 0; yp < 7; yp++) {
- if (finder[yp] & 0x40 >> xp) {
- grid[((yp + y) * size) + (xp + x)] = 0x11;
- } else {
- grid[((yp + y) * size) + (xp + x)] = 0x10;
- }
+ grid[((yp + y) * size) + (xp + x)] = 0x10 + !!(finder[yp] & (0x40 >> xp));
}
}
}
@@ -901,11 +890,7 @@ static void qr_place_align(unsigned char grid[], const int size, int x, int y) {
for (xp = 0; xp < 5; xp++) {
for (yp = 0; yp < 5; yp++) {
- if (alignment[yp] & 0x10 >> xp) {
- grid[((yp + y) * size) + (xp + x)] = 0x11;
- } else {
- grid[((yp + y) * size) + (xp + x)] = 0x10;
- }
+ grid[((yp + y) * size) + (xp + x)] = 0x10 + !!(alignment[yp] & (0x10 >> xp));
}
}
}
@@ -1020,16 +1005,16 @@ static void qr_populate_grid(unsigned char *grid, const int h_size, const int v_
int x = x_start - (row * 2);
int r = y * h_size;
- if ((x < 6) && (not_rmqr))
+ if (x < 6 && not_rmqr)
x--; /* skip over vertical timing pattern */
- if (!(grid[r + (x + 1)] & 0xf0)) {
+ if (!(grid[r + (x + 1)] & 0xF0)) {
grid[r + (x + 1)] = qr_cwbit(fullstream, i);
i++;
}
if (i < n) {
- if (!(grid[r + x] & 0xf0)) {
+ if (!(grid[r + x] & 0xF0)) {
grid[r + x] = qr_cwbit(fullstream, i);
i++;
}
@@ -1159,9 +1144,8 @@ static int qr_evaluate(unsigned char *local, const int size) {
for (x = 0; x < size - 1; x++) {
for (y = 0; y < size - 1; y++) {
k = local[(y * size) + x];
- if (((k == local[((y + 1) * size) + x]) &&
- (k == local[(y * size) + (x + 1)])) &&
- (k == local[((y + 1) * size) + (x + 1)])) {
+ if (k == local[((y + 1) * size) + x] && k == local[(y * size) + (x + 1)]
+ && k == local[((y + 1) * size) + (x + 1)]) {
result += 3;
}
}
@@ -1178,12 +1162,12 @@ static int qr_evaluate(unsigned char *local, const int size) {
/* Vertical */
for (x = 0; x < size; x++) {
for (y = 0; y <= (size - 7); y++) {
- if (local[y * size + x] && !local[(y + 1) * size + x] && local[(y + 2) * size + x] &&
- local[(y + 3) * size + x] && local[(y + 4) * size + x] &&
- !local[(y + 5) * size + x] && local[(y + 6) * size + x]) {
+ if (local[y * size + x] && !local[(y + 1) * size + x] && local[(y + 2) * size + x]
+ && local[(y + 3) * size + x] && local[(y + 4) * size + x]
+ && !local[(y + 5) * size + x] && local[(y + 6) * size + x]) {
/* Pattern found, check before and after */
beforeCount = 0;
- for (b = (y - 1); b >= (y - 4); b--) {
+ for (b = y - 1; b >= y - 4; b--) {
if (b < 0) { /* Count < edge as whitespace */
beforeCount = 4;
break;
@@ -1198,7 +1182,7 @@ static int qr_evaluate(unsigned char *local, const int size) {
result += 40;
} else {
afterCount = 0;
- for (a = (y + 7); a <= (y + 10); a++) {
+ for (a = y + 7; a <= y + 10; a++) {
if (a >= size) { /* Count > edge as whitespace */
afterCount = 4;
break;
@@ -1225,7 +1209,7 @@ static int qr_evaluate(unsigned char *local, const int size) {
if (memcmp(local + r + x, h1011101, 7) == 0) {
/* Pattern found, check before and after */
beforeCount = 0;
- for (b = (x - 1); b >= (x - 4); b--) {
+ for (b = x - 1; b >= x - 4; b--) {
if (b < 0) { /* Count < edge as whitespace */
beforeCount = 4;
break;
@@ -1241,7 +1225,7 @@ static int qr_evaluate(unsigned char *local, const int size) {
result += 40;
} else {
afterCount = 0;
- for (a = (x + 7); a <= (x + 10); a++) {
+ for (a = x + 7; a <= x + 10; a++) {
if (a >= size) { /* Count > edge as whitespace */
afterCount = 4;
break;
@@ -1342,7 +1326,7 @@ static int qr_apply_bitmask(unsigned char *grid, const int size, const int ecc_l
for (x = 0; x < size; x++) {
/* all eight bitmask variants are encoded in the 8 bits of the bytes that make up the mask array. */
- if (!(grid[r + x] & 0xf0)) { /* exclude areas not to be masked. */
+ if (!(grid[r + x] & 0xF0)) { /* exclude areas not to be masked. */
if (((y + x) & 1) == 0) {
mask[r + x] |= 0x01;
}
@@ -1351,26 +1335,26 @@ static int qr_apply_bitmask(unsigned char *grid, const int size, const int ecc_l
mask[r + x] |= 0x02;
}
}
- if ((x % 3) == 0) {
+ if (x % 3 == 0) {
mask[r + x] |= 0x04;
}
if (!fast_encode) {
- if (((y + x) % 3) == 0) {
+ if ((y + x) % 3 == 0) {
mask[r + x] |= 0x08;
}
}
- if ((((y / 2) + (x / 3)) & 1) == 0) {
+ if (((y / 2 + x / 3) & 1) == 0) {
mask[r + x] |= 0x10;
}
if (!fast_encode) {
if ((y * x) % 6 == 0) { /* Equivalent to (y * x) % 2 + (y * x) % 3 == 0 */
mask[r + x] |= 0x20;
}
- if (((((y * x) & 1) + ((y * x) % 3)) & 1) == 0) {
+ if (((((y * x) & 1) + (y * x) % 3) & 1) == 0) {
mask[r + x] |= 0x40;
}
}
- if (((((y + x) & 1) + ((y * x) % 3)) & 1) == 0) {
+ if (((((y + x) & 1) + (y * x) % 3) & 1) == 0) {
mask[r + x] |= 0x80;
}
}
@@ -1393,7 +1377,7 @@ static int qr_apply_bitmask(unsigned char *grid, const int size, const int ecc_l
if (mask[k] & bit) {
local[k] = grid[k] ^ 0x01;
} else {
- local[k] = grid[k] & 0x0f;
+ local[k] = grid[k] & 0x0F;
}
}
qr_add_format_info(local, size, ecc_level, pattern);
@@ -1464,7 +1448,7 @@ static int qr_blockLength(const int start, const char mode[], const int length)
do {
count++;
- } while (((i + count) < length) && (mode[i + count] == start_mode));
+ } while (i + count < length && mode[i + count] == start_mode);
return count;
}
@@ -1505,7 +1489,7 @@ static int qr_calc_binlen(const int version, char mode[], const unsigned int dda
break;
case 'B':
for (j = i; j < (i + blocklength); j++) {
- if (ddata[j] > 0xff) {
+ if (ddata[j] > 0xFF) {
count += 16;
} else {
count += 8;
@@ -1726,14 +1710,14 @@ INTERNAL int zint_qrcode(struct zint_symbol *symbol, struct zint_seg segs[], con
est_binlen = qr_calc_binlen_segs(40, mode, ddata, local_segs, seg_count, p_structapp, 0 /*mode_preset*/, gs1,
debug_print);
- if ((symbol->option_1 >= 1) && (symbol->option_1 <= 4)) {
+ if (symbol->option_1 >= 1 && symbol->option_1 <= 4) {
ecc_level = symbol->option_1 - 1;
} else {
ecc_level = QR_LEVEL_L;
}
max_cw = qr_data_codewords[ecc_level][39];
- if (est_binlen > (8 * max_cw)) {
+ if (est_binlen > 8 * max_cw) {
if (ecc_level == QR_LEVEL_L) {
return ZEXT z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 567,
"Input too long, requires %1$d codewords (maximum %2$d)", (est_binlen + 7) / 8,
@@ -1746,7 +1730,7 @@ INTERNAL int zint_qrcode(struct zint_symbol *symbol, struct zint_seg segs[], con
autosize = 40;
for (i = 39; i >= 0; i--) {
- if ((8 * qr_data_codewords[ecc_level][i]) >= est_binlen) {
+ if (8 * qr_data_codewords[ecc_level][i] >= est_binlen) {
autosize = i + 1;
}
}
@@ -1777,7 +1761,7 @@ INTERNAL int zint_qrcode(struct zint_symbol *symbol, struct zint_seg segs[], con
est_binlen = qr_calc_binlen_segs(autosize - 1, mode, ddata, local_segs, seg_count, p_structapp,
0 /*mode_preset*/, gs1, debug_print);
- if ((8 * qr_data_codewords[ecc_level][autosize - 2]) < est_binlen) {
+ if (8 * qr_data_codewords[ecc_level][autosize - 2] < est_binlen) {
canShrink = 0;
}
@@ -1794,7 +1778,7 @@ INTERNAL int zint_qrcode(struct zint_symbol *symbol, struct zint_seg segs[], con
version = autosize;
- if ((symbol->option_2 >= 1) && (symbol->option_2 <= 40)) {
+ if (symbol->option_2 >= 1 && symbol->option_2 <= 40) {
/* If the user has selected a larger symbol than the smallest available,
then use the size the user has selected, and re-optimise for this
symbol size.
@@ -1981,15 +1965,9 @@ static void microqr_setup_grid(unsigned char *grid, const int size) {
/* Add timing patterns */
for (i = 0; i < size; i++) {
- if (toggle == 1) {
- grid[i] = 0x21;
- grid[(i * size)] = 0x21;
- toggle = 0;
- } else {
- grid[i] = 0x20;
- grid[(i * size)] = 0x20;
- toggle = 1;
- }
+ grid[i] = 0x20 + toggle;
+ grid[i * size] = 0x20 + toggle;
+ toggle = !toggle;
}
/* Add finder patterns */
@@ -2022,22 +2000,14 @@ static void microqr_populate_grid(unsigned char *grid, const int size, const cha
do {
int x = (size - 2) - (row * 2);
- if (!(grid[(y * size) + (x + 1)] & 0xf0)) {
- if (full_stream[i] == '1') {
- grid[(y * size) + (x + 1)] = 0x01;
- } else {
- grid[(y * size) + (x + 1)] = 0x00;
- }
+ if (!(grid[(y * size) + (x + 1)] & 0xF0)) {
+ grid[(y * size) + (x + 1)] = full_stream[i] == '1';
i++;
}
if (i < bp) {
- if (!(grid[(y * size) + x] & 0xf0)) {
- if (full_stream[i] == '1') {
- grid[(y * size) + x] = 0x01;
- } else {
- grid[(y * size) + x] = 0x00;
- }
+ if (!(grid[(y * size) + x] & 0xF0)) {
+ grid[(y * size) + x] = full_stream[i] == '1';
i++;
}
}
@@ -2108,20 +2078,20 @@ static int microqr_apply_bitmask(unsigned char *grid, const int size, const int
r = y * size;
for (x = 0; x < size; x++) {
- if (!(grid[r + x] & 0xf0)) {
+ if (!(grid[r + x] & 0xF0)) {
if ((y & 1) == 0) {
mask[r + x] |= 0x01;
}
- if ((((y / 2) + (x / 3)) & 1) == 0) {
+ if (((y / 2 + x / 3) & 1) == 0) {
mask[r + x] |= 0x02;
}
- if (((((y * x) & 1) + ((y * x) % 3)) & 1) == 0) {
+ if (((((y * x) & 1) + (y * x) % 3) & 1) == 0) {
mask[r + x] |= 0x04;
}
- if (((((y + x) & 1) + ((y * x) % 3)) & 1) == 0) {
+ if (((((y + x) & 1) + (y * x) % 3) & 1) == 0) {
mask[r + x] |= 0x08;
}
}
@@ -2133,7 +2103,7 @@ static int microqr_apply_bitmask(unsigned char *grid, const int size, const int
} else {
for (k = 0; k < size_squared; k++) {
if (grid[k] & 0x01) {
- eval[k] = mask[k] ^ 0xff;
+ eval[k] = mask[k] ^ 0xFF;
} else {
eval[k] = mask[k];
}
@@ -2312,7 +2282,7 @@ INTERNAL int zint_microqr(struct zint_symbol *symbol, unsigned char source[], in
}
/* Get version from user */
- if ((symbol->option_2 >= 1) && (symbol->option_2 <= 4)) {
+ if (symbol->option_2 >= 1 && symbol->option_2 <= 4) {
if (symbol->option_2 == 1 && (i = z_not_sane(NEON_F, source, length))) {
return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 758,
"Invalid character at position %d in input for Version M1 (digits only)", i);
@@ -2530,24 +2500,14 @@ static void rmqr_setup_grid(unsigned char *grid, const int h_size, const int v_s
/* Add timing patterns - top and bottom */
for (i = 0; i < h_size; i++) {
- if (i % 2) {
- grid[i] = 0x20;
- grid[((v_size - 1) * h_size) + i] = 0x20;
- } else {
- grid[i] = 0x21;
- grid[((v_size - 1) * h_size) + i] = 0x21;
- }
+ grid[i] = 0x20 + !(i & 1);
+ grid[((v_size - 1) * h_size) + i] = 0x20 + !(i & 1);
}
/* Add timing patterns - left and right */
for (i = 0; i < v_size; i++) {
- if (i % 2) {
- grid[i * h_size] = 0x20;
- grid[(i * h_size) + (h_size - 1)] = 0x20;
- } else {
- grid[i * h_size] = 0x21;
- grid[(i * h_size) + (h_size - 1)] = 0x21;
- }
+ grid[i * h_size] = 0x20 + !(i & 1);
+ grid[(i * h_size) + (h_size - 1)] = 0x20 + !(i & 1);
}
/* Add finder pattern */
@@ -2556,11 +2516,7 @@ static void rmqr_setup_grid(unsigned char *grid, const int h_size, const int v_s
/* Add finder sub-pattern to bottom right */
for (i = 0; i < 5; i++) {
for (j = 0; j < 5; j++) {
- if (alignment[j] & 0x10 >> i) {
- grid[((v_size - 5) * h_size) + (h_size * i) + (h_size - 5) + j] = 0x11;
- } else {
- grid[((v_size - 5) * h_size) + (h_size * i) + (h_size - 5) + j] = 0x10;
- }
+ grid[((i + v_size - 5) * h_size) + (h_size - 5) + j] = 0x10 + !!(alignment[j] & (0x10 >> i));
}
}
@@ -2600,11 +2556,7 @@ static void rmqr_setup_grid(unsigned char *grid, const int h_size, const int v_s
if (finder_position != 0) {
for (j = 0; j < v_size; j++) {
- if (j % 2) {
- grid[(j * h_size) + finder_position] = 0x10;
- } else {
- grid[(j * h_size) + finder_position] = 0x11;
- }
+ grid[(j * h_size) + finder_position] = 0x10 + !(j & 1);
}
/* Top square */
@@ -2661,7 +2613,7 @@ INTERNAL int zint_rmqr(struct zint_symbol *symbol, struct zint_seg segs[], const
return z_errtxt(ZINT_ERROR_INVALID_OPTION, symbol, 577, "Error correction level Q not available in rMQR");
}
- if ((symbol->option_2 < 0) || (symbol->option_2 > 38)) {
+ if (symbol->option_2 < 0 || symbol->option_2 > 38) {
return z_errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 579, "Version '%d' out of range (1 to 38)",
symbol->option_2);
}
@@ -2691,7 +2643,7 @@ INTERNAL int zint_rmqr(struct zint_symbol *symbol, struct zint_seg segs[], const
ecc_level = symbol->option_1 == 4 ? QR_LEVEL_H : QR_LEVEL_M;
max_cw = rmqr_data_codewords[ecc_level >> 1][31];
- if (est_binlen > (8 * max_cw)) {
+ if (est_binlen > 8 * max_cw) {
return ZEXT z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 578,
"Input too long for ECC level %1$c, requires %2$d codewords (maximum %3$d)",
qr_ecc_level_names[ecc_level], (est_binlen + 7) / 8, max_cw);
@@ -2719,7 +2671,7 @@ INTERNAL int zint_rmqr(struct zint_symbol *symbol, struct zint_seg segs[], const
NULL /*p_structapp*/, 0 /*mode_preset*/, gs1, debug_print);
}
- if ((symbol->option_2 >= 1) && (symbol->option_2 <= 32)) {
+ if (symbol->option_2 >= 1 && symbol->option_2 <= 32) {
/* User specified symbol size */
version = symbol->option_2 - 1;
est_binlen = qr_calc_binlen_segs(RMQR_VERSION + version, mode, ddata, local_segs, seg_count,
@@ -2750,7 +2702,7 @@ INTERNAL int zint_rmqr(struct zint_symbol *symbol, struct zint_seg segs[], const
target_codewords = rmqr_data_codewords[ecc_level >> 1][version];
blocks = rmqr_blocks[ecc_level >> 1][version];
- if (est_binlen > (target_codewords * 8)) {
+ if (est_binlen > target_codewords * 8) {
/* User has selected a symbol too small for the data */
assert(symbol->option_2 > 0);
return ZEXT z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 560,
@@ -2794,9 +2746,9 @@ INTERNAL int zint_rmqr(struct zint_symbol *symbol, struct zint_seg segs[], const
for (i = 0; i < v_size; i++) {
int r = i * h_size;
for (j = 0; j < h_size; j++) {
- if ((grid[r + j] & 0xf0) == 0) {
+ if ((grid[r + j] & 0xF0) == 0) {
/* This is a data module */
- if (((i / 2) + (j / 3)) % 2 == 0) { /* < This is the data mask from section 7.8.2 */
+ if ((i / 2 + j / 3) % 2 == 0) { /* < This is the data mask from section 7.8.2 */
/* This module needs to be changed */
grid[r + j] ^= 0x01;
}
@@ -2815,8 +2767,7 @@ INTERNAL int zint_rmqr(struct zint_symbol *symbol, struct zint_seg segs[], const
for (i = 0; i < 5; i++) {
for (j = 0; j < 3; j++) {
grid[(h_size * (i + 1)) + j + 8] = (left_format_info >> ((j * 5) + i)) & 0x01;
- grid[(h_size * (v_size - 6)) + (h_size * i) + j + (h_size - 8)]
- = (right_format_info >> ((j * 5) + i)) & 0x01;
+ grid[(h_size * (i + v_size - 6)) + j + (h_size - 8)] = (right_format_info >> ((j * 5) + i)) & 0x01;
}
}
grid[(h_size * 1) + 11] = (left_format_info >> 15) & 0x01;
diff --git a/backend/raster.c b/backend/raster.c
index d0689028..edbd3bd0 100644
--- a/backend/raster.c
+++ b/backend/raster.c
@@ -83,10 +83,10 @@ static int buffer_plot(struct zint_symbol *symbol, const unsigned char *pixelbuf
{0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, /* 0x20-2F */
{0} /*bg*/, {0} /*fg*/, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, /* 0-9 */
{0}, {0}, {0}, {0}, {0}, {0}, {0}, /* :;<=>?@ */
- {0}, { 0, 0, 0xff } /*Blue*/, { 0, 0xff, 0xff } /*Cyan*/, {0}, {0}, {0}, { 0, 0xff, 0 } /*Green*/, /* A-G */
- {0}, {0}, {0}, { 0, 0, 0 } /*blacK*/, {0}, { 0xff, 0, 0xff } /*Magenta*/, {0}, /* H-N */
- {0}, {0}, {0}, { 0xff, 0, 0 } /*Red*/, {0}, {0}, {0}, {0}, /* O-V */
- { 0xff, 0xff, 0xff } /*White*/, {0}, { 0xff, 0xff, 0 } /*Yellow*/, {0} /* W-Z */
+ {0}, { 0, 0, 0xFF } /*Blue*/, { 0, 0xFF, 0xFF } /*Cyan*/, {0}, {0}, {0}, { 0, 0xFF, 0 } /*Green*/, /* A-G */
+ {0}, {0}, {0}, { 0, 0, 0 } /*blacK*/, {0}, { 0xFF, 0, 0xFF } /*Magenta*/, {0}, /* H-N */
+ {0}, {0}, {0}, { 0xFF, 0, 0 } /*Red*/, {0}, {0}, {0}, {0}, /* O-V */
+ { 0xFF, 0xFF, 0xFF } /*White*/, {0}, { 0xFF, 0xFF, 0 } /*Yellow*/, {0} /* W-Z */
};
int row;
int plot_alpha = 0;
@@ -340,7 +340,7 @@ static void draw_letter(unsigned char *pixelbuf, const unsigned char letter, int
return;
}
- if ((letter >= 127) && (letter < 161)) {
+ if (letter >= 127 && letter < 161) {
return;
}
@@ -493,7 +493,7 @@ static void draw_circle(unsigned char *pixelbuf, const int image_width, const in
for (y = -radius_i; y <= radius_i; y++) {
const int y_squared = y * y;
for (x = -radius_i; x <= radius_i; x++) {
- if ((x * x) + y_squared <= radius_squared) {
+ if (x * x + y_squared <= radius_squared) {
draw_pt(pixelbuf, image_width, image_height, x0 + x, y0 + y, fill);
}
}
@@ -1080,7 +1080,7 @@ static int plot_raster_default(struct zint_symbol *symbol, const int rotate_angl
const int fill = z_module_is_set(symbol, r, i);
for (block_width = 1; (i + block_width < symbol->width)
&& z_module_is_set(symbol, r, i + block_width) == fill; block_width++);
- if ((r == (symbol->rows - 1)) && (i > main_width) && (addon_latch == 0)) {
+ if (r == symbol->rows - 1 && i > main_width && addon_latch == 0) {
int addon_row_height_si;
const int addon_row_adj_si = (int) ceilf((font_height + symbol->text_gap) * si);
copy_bar_line(pixelbuf, xoffset_si, main_width * si, yposn_si, row_height_si, image_width,
diff --git a/backend/rss.c b/backend/rss.c
index 70ce78eb..4a558075 100644
--- a/backend/rss.c
+++ b/backend/rss.c
@@ -72,7 +72,7 @@
/* `combins()' in ISO/IEC 24724:2011 Annex B */
/****************************************************************************
* dbar_combins(n,r): returns the number of Combinations of r selected from n:
- * Combinations = n! / ((n - r)! * r!)
+ * Combinations = n! / (n - r)! * r!
****************************************************************************/
static int dbar_combins(const int n, const int r) {
int i;
@@ -126,7 +126,7 @@ static void dbar_getWidths(int widths[], int val, int n, const int elements, con
/* Get all combinations */
subVal = dbar_combins(n - elmWidth - 1, elements - bar - 2);
/* Less combinations with no single-module element */
- if (noNarrow && !narrowMask && (n - elmWidth - (elements - bar - 1) >= elements - bar - 1)) {
+ if (noNarrow && !narrowMask && n - elmWidth - (elements - bar - 1) >= elements - bar - 1) {
subVal -= dbar_combins(n - elmWidth - (elements - bar), elements - bar - 2);
}
/* Less combinations with elements > maxVal */
@@ -1256,7 +1256,7 @@ INTERNAL int zint_dbar_exp_cc(struct zint_symbol *symbol, unsigned char source[]
cols_per_row = 2; /* Default */
if (symbol->option_2 >= 1 && symbol->option_2 <= 11) {
cols_per_row = symbol->option_2;
- if (cc_rows && (cols_per_row == 1)) {
+ if (cc_rows && cols_per_row == 1) {
/* "There shall be a minimum of four symbol characters in the
first row of an RSS Expanded Stacked symbol when it is the linear
component of an EAN.UCC Composite symbol." */
@@ -1450,7 +1450,7 @@ INTERNAL int zint_dbar_exp_cc(struct zint_symbol *symbol, unsigned char source[]
}
reader++;
current_block++;
- } while ((reader < cols_per_row) && (current_block < codeblocks));
+ } while (reader < cols_per_row && current_block < codeblocks);
/* Row Stop */
sub_elements[elements_in_sub++] = 1; /* Right guard */
diff --git a/backend/svg.c b/backend/svg.c
index 3967957f..e20a8502 100644
--- a/backend/svg.c
+++ b/backend/svg.c
@@ -103,7 +103,7 @@ static void svg_put_fattrib(const char *prefix, const int dp, const float val, s
/* Helper to output opacity attribute attribute and close tag (maybe) */
static void svg_put_opacity_close(const unsigned char alpha, const float val, const int close, struct filemem *fmp) {
- if (alpha != 0xff) {
+ if (alpha != 0xFF) {
svg_put_fattrib(" opacity=\"", 3, val, fmp);
}
if (close) {
@@ -139,12 +139,12 @@ INTERNAL int zint_svg_plot(struct zint_symbol *symbol) {
char *html_string;
(void) zint_out_colour_get_rgb(symbol->fgcolour, &fgred, &fggreen, &fgblue, &fg_alpha);
- if (fg_alpha != 0xff) {
+ if (fg_alpha != 0xFF) {
fg_alpha_opacity = fg_alpha / 255.0f;
}
sprintf(fgcolour_string, "%02X%02X%02X", fgred, fggreen, fgblue);
(void) zint_out_colour_get_rgb(symbol->bgcolour, &bgred, &bggreen, &bgblue, &bg_alpha);
- if (bg_alpha != 0xff) {
+ if (bg_alpha != 0xFF) {
bg_alpha_opacity = bg_alpha / 255.0f;
}
sprintf(bgcolour_string, "%02X%02X%02X", bgred, bggreen, bgblue);
@@ -242,7 +242,7 @@ INTERNAL int zint_svg_plot(struct zint_symbol *symbol) {
half_radius = 0.25f * previous_diameter;
half_sqrt3_radius = 0.43301270189221932338f * previous_diameter;
}
- if ((hex->rotation == 0) || (hex->rotation == 180)) {
+ if (hex->rotation == 0 || hex->rotation == 180) {
zint_fm_putsf("M", 2, hex->x, fmp);
zint_fm_putsf(" ", 2, hex->y + radius, fmp);
zint_fm_putsf("L", 2, hex->x + half_sqrt3_radius, fmp);
diff --git a/backend/tests/test_filemem.c b/backend/tests/test_filemem.c
index fdf9a354..31fa5702 100644
--- a/backend/tests/test_filemem.c
+++ b/backend/tests/test_filemem.c
@@ -39,7 +39,7 @@
#include "../common.h"
#include "../filemem.h"
-static void test_svg(const testCtx *const p_ctx) {
+static void test_file(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
struct item {
@@ -68,6 +68,9 @@ static void test_svg(const testCtx *const p_ctx) {
" \n"
"\n"
},
+ /* 1*/ { BARCODE_TELEPEN, BARCODE_MEMORY_FILE, "out.txt", "ABCD", -1, 0,
+ "AA B8 BB B8 E3 B8 AE EA EB B8 AE AA E2 AA\n"
+ },
};
int data_size = ARRAY_SIZE(data);
int i, length, ret;
@@ -96,10 +99,12 @@ static void test_svg(const testCtx *const p_ctx) {
assert_nonnull(symbol->memfile, "i:%d memfile NULL (%s)\n", i, symbol->errtxt);
- assert_equal(symbol->memfile_size, expected_size, "i:%d memfile_size %d != %d (%s)\n",
- i, symbol->memfile_size, expected_size, symbol->errtxt);
+ assert_equal(symbol->memfile_size, expected_size, "i:%d memfile_size %d != %d (\"%.*s\", \"%s\") (%s)\n",
+ i, symbol->memfile_size, expected_size, symbol->memfile_size, symbol->memfile,
+ data[i].expected, symbol->errtxt);
ret = memcmp(symbol->memfile, data[i].expected, expected_size);
- assert_zero(ret, "i:%d memcmp() %d != 0\n", i, ret);
+ assert_zero(ret, "i:%d memcmp(\"%.*s\", \"%s\") %d != 0 (%s)\n",
+ i, symbol->memfile_size, symbol->memfile, data[i].expected, ret, symbol->errtxt);
} else {
assert_null(symbol->memfile, "i:%d memfile != NULL (%s)\n", i, symbol->errtxt);
assert_zero(symbol->memfile_size, "i:%d memfile_size != 0 (%s)\n", i, symbol->errtxt);
@@ -467,7 +472,7 @@ static void test_large(const testCtx *const p_ctx) {
int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func */
- { "test_svg", test_svg },
+ { "test_file", test_file },
{ "test_putsf", test_putsf },
{ "test_printf", test_printf },
{ "test_seek", test_seek },
diff --git a/backend/tests/test_library.c b/backend/tests/test_library.c
index c919e64c..f9210a1d 100644
--- a/backend/tests/test_library.c
+++ b/backend/tests/test_library.c
@@ -1577,7 +1577,7 @@ static void test_encode_print_outfile_directory(const testCtx *const p_ctx) {
int ret;
struct zint_symbol *symbol = NULL;
char dirname[] = "outdir.txt";
- char expected[] = "Error 201: Could not open output file";
+ char expected[] = "Error 201: Could not open TXT output file"; /* Excluding OS-dependent `errno` stuff */
(void)p_ctx;
@@ -1593,7 +1593,8 @@ static void test_encode_print_outfile_directory(const testCtx *const p_ctx) {
strcpy(symbol->outfile, dirname);
ret = ZBarcode_Encode_and_Print(symbol, TCU("1"), 0, 0);
assert_equal(ret, ZINT_ERROR_FILE_ACCESS, "ret %d != ZINT_ERROR_FILE_ACCESS (%s)\n", ret, symbol->errtxt);
- assert_zero(strcmp(symbol->errtxt, expected), "strcmp(%s, %s) != 0\n", symbol->errtxt, expected);
+ assert_zero(strncmp(symbol->errtxt, expected, sizeof(expected) - 1), "strncmp(%s, %s) != 0\n",
+ symbol->errtxt, expected);
ret = testUtilRmDir(dirname);
assert_zero(ret, "testUtilRmDir(%s) %d != 0 (%d: %s)\n", dirname, ret, errno, strerror(errno));
diff --git a/backend/ultra.c b/backend/ultra.c
index bb9257b9..922f9489 100644
--- a/backend/ultra.c
+++ b/backend/ultra.c
@@ -196,19 +196,19 @@ static void ult_gf283(const short DataSize, const short EccSize, int Message[])
ult_genPoly(EccSize, gPoly, gfPwr, gfLog);
/* zero all EccSize codeword values */
- for (j = 281; (j > (281 - EccSize)); j--) Message[j] = 0;
+ for (j = 281; j > 281 - EccSize; j--) Message[j] = 0;
/* shift message codewords to the right, leave space for ECC checkwords */
- for (i = DataSize - 1; (i >= 0); j--, i--) Message[j] = Message[i];
+ for (i = DataSize - 1; i >= 0; j--, i--) Message[j] = Message[i];
/* add zeroes to pad left end Message[] for truncated codewords */
j++;
for (i = 0; i < j; i++) Message[i] = 0;
/* generate (EccSize) Reed-Solomon checkwords */
- for (n = j; n < (j + DataSize); n++) {
+ for (n = j; n < j + DataSize; n++) {
t = (Message[j + DataSize] + Message[n]) % 283;
- for (i = 0; i < (EccSize - 1); i++) {
+ for (i = 0; i < EccSize - 1; i++) {
Message[j + DataSize + i] = (Message[j + DataSize + i + 1] + 283
- ULT_GFMUL(t, gPoly[EccSize - 1 - i])) % 283;
}
@@ -227,7 +227,7 @@ static int ult_find_fragment(const unsigned char source[], const int length, con
for (j = 0; j < 27; j++) {
latch = 0;
fraglen = (int) strlen(ult_fragment[j]);
- if ((position + fraglen) <= length) {
+ if (position + fraglen <= length) {
latch = 1;
for (k = 0; k < fraglen; k++) {
if (source[position + k] != ult_fragment[j][k]) {
@@ -258,7 +258,7 @@ static float ult_look_ahead_eightbit(const unsigned char source[], const int len
}
i = in_locn;
- while ((i < length) && (i < end_char)) {
+ while (i < length && i < end_char) {
if (gs1 && source[i] == '\x1D') {
cw[codeword_count] = 268; /* FNC1 */
} else {
@@ -284,7 +284,7 @@ static float ult_look_ahead_ascii(unsigned char source[], const int length, cons
const int gs1) {
int codeword_count = 0;
int i;
- int first_digit, second_digit, done;
+ int done;
int letters_encoded = 0;
if (current_mode == ULT_EIGHTBIT_MODE) {
@@ -306,35 +306,35 @@ static float ult_look_ahead_ascii(unsigned char source[], const int length, cons
/* Check for double digits */
done = 0;
if (i + 1 < length) {
- first_digit = z_posn(ult_digit, source[i]);
- second_digit = z_posn(ult_digit, source[i + 1]);
- if ((first_digit != -1) && (second_digit != -1)) {
+ const int first_digit = z_posn(ult_digit, source[i]);
+ const int second_digit = z_posn(ult_digit, source[i + 1]);
+ if (first_digit != -1 && second_digit != -1) {
/* Double digit can be encoded */
- if ((first_digit >= 0) && (first_digit <= 9) && (second_digit >= 0) && (second_digit <= 9)) {
+ if (first_digit >= 0 && first_digit <= 9 && second_digit >= 0 && second_digit <= 9) {
/* Double digit numerics */
cw[codeword_count] = (10 * first_digit) + second_digit + 128;
codeword_count++;
i += 2;
done = 1;
- } else if ((first_digit >= 0) && (first_digit <= 9) && (second_digit == 10)) {
+ } else if (first_digit >= 0 && first_digit <= 9 && second_digit == 10) {
/* Single digit followed by selected decimal point character */
cw[codeword_count] = first_digit + 228;
codeword_count++;
i += 2;
done = 1;
- } else if ((first_digit == 10) && (second_digit >= 0) && (second_digit <= 9)) {
+ } else if (first_digit == 10 && second_digit >= 0 && second_digit <= 9) {
/* Selected decimal point character followed by single digit */
cw[codeword_count] = second_digit + 238;
codeword_count++;
i += 2;
done = 1;
- } else if ((first_digit >= 0) && (first_digit <= 9) && (second_digit == 11)) {
+ } else if (first_digit >= 0 && first_digit <= 9 && second_digit == 11) {
/* Single digit or decimal point followed by field deliminator */
cw[codeword_count] = first_digit + 248;
codeword_count++;
i += 2;
done = 1;
- } else if ((first_digit == 11) && (second_digit >= 0) && (second_digit <= 9)) {
+ } else if (first_digit == 11 && second_digit >= 0 && second_digit <= 9) {
/* Field deliminator followed by single digit or decimal point */
cw[codeword_count] = second_digit + 259;
codeword_count++;
@@ -353,7 +353,7 @@ static float ult_look_ahead_ascii(unsigned char source[], const int length, cons
codeword_count++;
i++;
}
- } while ((i < length) && (i < end_char) && (source[i] < 0x80));
+ } while (i < length && i < end_char && source[i] < 0x80);
letters_encoded = i - in_locn;
if (encoded != NULL) {
@@ -413,7 +413,7 @@ static int ult_get_subset(const unsigned char source[], const int length, const
int subset = 0;
fragno = ult_find_fragment(source, length, in_locn);
- if ((fragno != -1) && (fragno != 26)) {
+ if (fragno != -1 && fragno != 26) {
subset = 3;
} else if (current_subset == 2) {
if (z_posn(ult_c43_set2, source[in_locn]) != -1) {
@@ -458,7 +458,7 @@ static float ult_look_ahead_c43(const unsigned char source[], const int length,
/* Check for permissable URL C43 macro sequences, otherwise encode directly */
fragno = ult_find_fragment(source, length, sublocn);
- if ((fragno == 2) || (fragno == 3)) {
+ if (fragno == 2 || fragno == 3) {
/* http://www. > http:// */
/* https://www. > https:// */
fragno -= 2;
@@ -499,7 +499,7 @@ static float ult_look_ahead_c43(const unsigned char source[], const int length,
if (subset == 1) {
cw[codeword_count] = 260; /* C43 Compaction Submode C1 */
codeword_count++;
- } else if ((subset == 2) || (subset == 3)) {
+ } else if (subset == 2 || subset == 3) {
cw[codeword_count] = 266; /* C43 Compaction Submode C2 */
codeword_count++;
}
@@ -510,14 +510,14 @@ static float ult_look_ahead_c43(const unsigned char source[], const int length,
if (subset == 1) {
cw[codeword_count] = 278; /* C43 Compaction Submode C1 */
codeword_count++;
- } else if ((subset == 2) || (subset == 3)) {
+ } else if (subset == 2 || subset == 3) {
cw[codeword_count] = 280; /* C43 Compaction Submode C2 */
codeword_count++;
}
}
unshift_set = subset;
- while ((sublocn < length) && (sublocn < end_char)) {
+ while (sublocn < length && sublocn < end_char) {
/* Check for FNC1 */
if (gs1 && source[sublocn] == '\x1D') {
break;
@@ -529,7 +529,7 @@ static float ult_look_ahead_c43(const unsigned char source[], const int length,
break;
}
- if ((new_subset != subset) && ((new_subset == 1) || (new_subset == 2))) {
+ if (new_subset != subset && (new_subset == 1 || new_subset == 2)) {
if (ult_c43_should_latch_other(source, length, sublocn, subset)) {
subcw[subcodeword_count] = 42; /* Latch to other C43 set */
subcodeword_count++;
@@ -681,10 +681,10 @@ static int ult_generate_codewords(struct zint_symbol *symbol, const unsigned cha
mode[input_locn] = 'a';
current_mode = ULT_ASCII_MODE;
- if ((c43_score > ascii_score) && (c43_score > eightbit_score)) {
+ if (c43_score > ascii_score && c43_score > eightbit_score) {
mode[input_locn] = 'c';
current_mode = ULT_C43_MODE;
- } else if ((eightbit_score > ascii_score) && (eightbit_score > c43_score)) {
+ } else if (eightbit_score > ascii_score && eightbit_score > c43_score) {
mode[input_locn] = '8';
current_mode = ULT_EIGHTBIT_MODE;
}
@@ -846,14 +846,14 @@ static int ult_generate_codewords_segs(struct zint_symbol *symbol, struct zint_s
codewords[0] = 272;
}
} else {
- if ((eci >= 3) && (eci <= 18) && (eci != 14)) {
+ if (eci >= 3 && eci <= 18 && eci != 14) {
/* ECI indicates use of character set within ISO/IEC 8859 */
codewords[0] = 257 + (eci - 3);
if (codewords[0] > 267) {
/* Avoids ECI 14 for non-existant ISO/IEC 8859-12 */
codewords[0]--;
}
- } else if ((eci > 18) && (eci <= 898)) {
+ } else if (eci > 18 && eci <= 898) {
/* ECI indicates use of character set outside ISO/IEC 8859 */
codewords[0] = 275 + (eci / 256);
codewords[1] = eci % 256;
@@ -861,7 +861,7 @@ static int ult_generate_codewords_segs(struct zint_symbol *symbol, struct zint_s
} else if (eci == 899) {
/* Non-language byte data */
codewords[0] = 280;
- } else if ((eci > 899) && (eci <= 9999)) {
+ } else if (eci > 899 && eci <= 9999) {
/* ECI beyond 899 needs to use fixed length encodable ECI invocation (section 7.6.2) */
/* Encode as 3 codewords */
codewords[0] = 257; /* ISO/IEC 8859-1 used to enter 8-bit mode */
@@ -882,18 +882,18 @@ static int ult_generate_codewords_segs(struct zint_symbol *symbol, struct zint_s
}
}
- if ((codewords[0] == 257) || (codewords[0] == 272)) {
+ if (codewords[0] == 257 || codewords[0] == 272) {
int fragno = ult_find_fragment(source, length, 0);
/* Check for http:// at start of input */
- if ((fragno == 0) || (fragno == 2)) {
+ if (fragno == 0 || fragno == 2) {
codewords[0] = 281;
source += 7;
length -= 7;
symbol_mode = ULT_EIGHTBIT_MODE;
/* Check for https:// at start of input */
- } else if ((fragno == 1) || (fragno == 3)) {
+ } else if (fragno == 1 || fragno == 3) {
codewords[0] = 282;
source += 8;
length -= 8;
@@ -1025,7 +1025,7 @@ INTERNAL int zint_ultra(struct zint_symbol *symbol, struct zint_seg segs[], cons
}
/* Default ECC level is EC2 */
- if ((symbol->option_1 <= 0) || (symbol->option_1 > 6)) {
+ if (symbol->option_1 <= 0 || symbol->option_1 > 6) {
ecc_level = 2;
} else {
ecc_level = symbol->option_1 - 1;
@@ -1035,7 +1035,7 @@ INTERNAL int zint_ultra(struct zint_symbol *symbol, struct zint_seg segs[], cons
if (ecc_level == 0) {
qcc = 3;
} else {
- if ((data_cw_count % 25) == 0) {
+ if (data_cw_count % 25 == 0) {
qcc = ult_kec[ecc_level] * (data_cw_count / 25) + 3 + 2;
} else {
qcc = ult_kec[ecc_level] * ((data_cw_count / 25) + 1) + 3 + 2;
@@ -1081,7 +1081,7 @@ INTERNAL int zint_ultra(struct zint_symbol *symbol, struct zint_seg segs[], cons
}
}
- if ((total_cws % rows) == 0) {
+ if (total_cws % rows == 0) {
pads = 0;
columns = total_cws / rows;
} else {
@@ -1199,7 +1199,7 @@ INTERNAL int zint_ultra(struct zint_symbol *symbol, struct zint_seg segs[], cons
for (j = 0; j < 5; j++) {
tilepat[4 - j] = ult_colour[(ult_tiles[codeword[i]] >> (3 * j)) & 0x07];
}
- if ((tiley + 1) >= total_height) {
+ if (tiley + 1 >= total_height) {
tiley = 0;
tilex++;
diff --git a/backend/upcean.c b/backend/upcean.c
index a8a4bcc7..71baa0fb 100644
--- a/backend/upcean.c
+++ b/backend/upcean.c
@@ -222,7 +222,7 @@ static int upce_cc(struct zint_symbol *symbol, unsigned char source[], int lengt
equivalent[3] = source[2];
equivalent[9] = source[3];
equivalent[10] = source[4];
- if (((source[2] == '0') || (source[2] == '1')) || (source[2] == '2')) {
+ if (source[2] == '0' || source[2] == '1' || source[2] == '2') {
/* Note 1 - "X3 shall not be equal to 0, 1 or 2" */
return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 271,
"For this UPC-E zero suppression, 3rd character cannot be \"0\", \"1\" or \"2\" (%.*s)",
@@ -432,7 +432,7 @@ static int ean13_cc(struct zint_symbol *symbol, const unsigned char source[], in
d += 5;
}
- if (((i > 1) && (i < 7)) && (parity[i - 2] == 'B')) {
+ if (i > 1 && i < 7 && parity[i - 2] == 'B') {
memcpy(d, EANsetB[gtin[i] - '0'], 4);
} else {
memcpy(d, EANsetA[gtin[i] - '0'], 4);
@@ -561,8 +561,7 @@ static int isbnx(struct zint_symbol *symbol, unsigned char source[], const int l
}
if (length == 13) /* Using 13 character ISBN */ {
- if (!(((source[0] == '9') && (source[1] == '7')) &&
- ((source[2] == '8') || (source[2] == '9')))) {
+ if (source[0] != '9' || source[1] != '7' || (source[2] != '8' && source[2] != '9')) {
return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 279,
"Invalid ISBN (must begin with \"978\" or \"979\")");
}
diff --git a/backend/vector.c b/backend/vector.c
index c966e172..7dd7cedb 100644
--- a/backend/vector.c
+++ b/backend/vector.c
@@ -218,7 +218,7 @@ static void vector_scale(struct zint_symbol *symbol, const int file_type) {
scale = 0.2f;
}
- if ((file_type == OUT_EMF_FILE) && (symbol->symbology == BARCODE_MAXICODE)) {
+ if (file_type == OUT_EMF_FILE && symbol->symbology == BARCODE_MAXICODE) {
/* Increase size to overcome limitations in EMF file format */
scale *= 20;
}
@@ -355,7 +355,7 @@ static void vector_rotate(struct zint_symbol *symbol, const int rotate_angle) {
string = string->next;
}
- if ((rotate_angle == 90) || (rotate_angle == 270)) {
+ if (rotate_angle == 90 || rotate_angle == 270) {
temp = symbol->vector->height;
symbol->vector->height = symbol->vector->width;
symbol->vector->width = temp;
@@ -372,8 +372,8 @@ static void vector_reduce_rectangles(struct zint_symbol *symbol) {
target = prev->next;
while (target) {
- if ((rect->x == target->x) && (rect->width == target->width)
- && (z_stripf(rect->y + rect->height) == target->y) && (rect->colour == target->colour)) {
+ if (rect->x == target->x && rect->width == target->width && z_stripf(rect->y + rect->height) == target->y
+ && rect->colour == target->colour) {
rect->height += target->height;
prev->next = target->next;
free(target);
@@ -492,7 +492,7 @@ INTERNAL int zint_plot_vector(struct zint_symbol *symbol, int rotate_angle, int
xoffset_comp = xoffset + comp_xoffset;
- if ((symbol->symbology != BARCODE_MAXICODE) && (symbol->output_options & BARCODE_DOTTY_MODE)) {
+ if (symbol->symbology != BARCODE_MAXICODE && (symbol->output_options & BARCODE_DOTTY_MODE)) {
if (symbol->dot_size < 1.0f) {
dot_overspill = 0.0f;
/* Offset (1 - dot_size) / 2 + dot_radius == (1 - dot_size + dot_size) / 2 == 1 / 2 */
@@ -623,7 +623,7 @@ INTERNAL int zint_plot_vector(struct zint_symbol *symbol, int rotate_angle, int
for (block_width = 1; (i + block_width < symbol->width)
&& z_module_is_set(symbol, r, i + block_width) == fill; block_width++);
- if ((r == (symbol->rows - 1)) && (i > main_width) && (addon_latch == 0)) {
+ if (r == symbol->rows - 1 && i > main_width && addon_latch == 0) {
addon_text_yposn = yposn + font_height - digit_ascender;
if (addon_text_yposn < 0.0f) {
addon_text_yposn = 0.0f;
diff --git a/docs/manual.html b/docs/manual.html
index d7296565..f818243e 100644
--- a/docs/manual.html
+++ b/docs/manual.html
@@ -333,7 +333,7 @@
Zint Barcode Generator and Zint Barcode Studio User
Manual
Version 2.15.0.9
-
April 2025
+
August 2025
Zint can output a representation of the symbol data as a set of
hexadecimal values if asked to output to a text file
("*.txt") or if given the option
---filetype=txt. This can be used for test and diagnostic
-purposes.
+--filetype=txt or the option --dump. This can
+be used for test and diagnostic purposes.
Additional options are available which are specific to certain
symbologies. These may, for example, control the amount of error
correction data or the size of the symbol. These options are discussed
diff --git a/docs/manual.pmd b/docs/manual.pmd
index 87f26242..32a5f3a4 100644
--- a/docs/manual.pmd
+++ b/docs/manual.pmd
@@ -1,6 +1,6 @@
% Zint Barcode Generator and Zint Barcode Studio User Manual
% Version 2.15.0.9
-% April 2025
+% August 2025
# 1. Introduction
@@ -1638,7 +1638,8 @@ The `-e` or `--ecinos` option gives a list of the ECI codes.
Zint can output a representation of the symbol data as a set of hexadecimal
values if asked to output to a text file (`"*.txt"`) or if given the option
-`--filetype=txt`. This can be used for test and diagnostic purposes.
+`--filetype=txt` or the option `--dump`. This can be used for test and
+diagnostic purposes.
Additional options are available which are specific to certain symbologies.
These may, for example, control the amount of error correction data or the size
diff --git a/docs/manual.txt b/docs/manual.txt
index 87b2f49e..86d758d5 100644
--- a/docs/manual.txt
+++ b/docs/manual.txt
@@ -1,6 +1,6 @@
Zint Barcode Generator and Zint Barcode Studio User Manual
Version 2.15.0.9
-April 2025
+August 2025
*******************************************************************************
* For reference the following is a text-only version of the Zint manual, *
@@ -1684,7 +1684,8 @@ The -e or --ecinos option gives a list of the ECI codes.
Zint can output a representation of the symbol data as a set of hexadecimal
values if asked to output to a text file ("*.txt") or if given the option
---filetype=txt. This can be used for test and diagnostic purposes.
+--filetype=txt or the option --dump. This can be used for test and diagnostic
+purposes.
Additional options are available which are specific to certain symbologies.
These may, for example, control the amount of error correction data or the size