1
0
mirror of https://git.code.sf.net/p/zint/code synced 2026-06-15 10:03:36 +00:00

library: use "filemem" for TXT dump_plot() -> txt_hex_plot()

filemem: remove NOLINTS (clang-tidy-20 bug fixed)
QRCODE: eliminate NOLINTs using some more asserts (clang-tidy-20);
  some "de-branching" of loops
general: various code fiddlings, in particular lessen no. of
  redundant parenthesized expressions, especially in conditionals,
  which reduce rather than aid readibility IMNSHO
manual: mention "--dump" option
This commit is contained in:
gitlost
2025-08-28 20:34:56 +01:00
parent 36364b4912
commit 44e2099a65
35 changed files with 507 additions and 588 deletions
+92 -104
View File
@@ -46,53 +46,44 @@
#define AZ_BIN_CAP_CWDS_S "1661" /* String version of (AZTEC_BIN_CAPACITY / 12) */ #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 */ /* 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) { static int az_count_doubles(const unsigned char source[], const int position, const int length) {
int c = 0; int i;
while ((i + 1 < length) && ((source[i] == '.') || (source[i] == ',')) && (source[i + 1] == ' ')) { for (i = position; i + 1 < length && (source[i] == '.' || source[i] == ',') && source[i + 1] == ' '; i += 2);
c++;
i += 2;
}
return c; return (i - position) >> 1;
} }
/* Count number of consecutive full stops or commas (can be encoded in Punct or Digit mode) */ /* 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) { static int az_count_dotcomma(const unsigned char source[], const int position, const int length) {
int c = 0; int i;
while (i < length && ((source[i] == '.') || (source[i] == ','))) { for (i = position; i < length && (source[i] == '.' || source[i] == ','); i++);
c++;
i++;
}
return c; return i - position;
} }
/* Count number of consecutive `chr`s */ /* Count number of consecutive `chr`s */
static int az_count_chr(const unsigned char source[], int i, const int length, const unsigned char chr) { static int az_count_chr(const unsigned char source[], const int position, const int length, const unsigned char chr) {
int c = 0; int i;
while (i < length && source[i] == chr) { for (i = position; i < length && source[i] == chr; i++);
c++;
i++;
}
return c; return i - position;
} }
/* Return mode following current, or 'E' if none */ /* Return mode following current, or 'E' if none */
static char az_get_next_mode(const char encode_mode[], const int src_len, int i) { static char az_get_next_mode(const char encode_mode[], const int length, int i) {
int current_mode = encode_mode[i]; const char current_mode = encode_mode[i];
do { do {
i++; i++;
} while ((i < src_len) && (encode_mode[i] == current_mode)); } while (i < length && encode_mode[i] == current_mode);
if (i >= src_len) {
if (i >= length) {
return 'E'; return 'E';
} else {
return encode_mode[i];
} }
return encode_mode[i];
} }
/* Same as `z_bin_append_posn()`, except check for buffer overflow first */ /* 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 */ /* 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) { const int gs1_bp, const int eci, char *p_current_mode, int *data_length, const int debug_print) {
int i, j; int i, j;
@@ -114,11 +105,11 @@ static int aztec_text_process(const unsigned char source[], int src_len, int bp,
int count; int count;
char next_mode; char next_mode;
int reduced_length; int reduced_length;
char *encode_mode = (char *) z_alloca(src_len + 1); char *encode_mode = (char *) z_alloca(length + 1);
unsigned char *reduced_source = (unsigned char *) z_alloca(src_len + 1); unsigned char *reduced_source = (unsigned char *) z_alloca(length + 1);
char *reduced_encode_mode = (char *) z_alloca(src_len + 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) { if (source[i] >= 128) {
encode_mode[i] = 'B'; encode_mode[i] = 'B';
} else if (gs1 && source[i] == '\x1D') { } 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 /* Deal first with letter combinations which can be combined to one codeword
Combinations are (CR LF) (. SP) (, SP) (: SP) in Punct mode */ Combinations are (CR LF) (. SP) (, SP) (: SP) in Punct mode */
current_mode = initial_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 */ /* 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] = 'P';
encode_mode[i + 1] = 'P'; encode_mode[i + 1] = 'P';
/* Combination (: SP) should always be in Punct mode */ /* 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'; encode_mode[i + 1] = 'P';
/* Combinations (. SP) and (, SP) sometimes use fewer bits in Digit mode */ /* Combinations (. SP) and (, SP) sometimes use fewer bits in Digit mode */
} else if (((source[i] == '.') || (source[i] == ',')) && (source[i + 1] == ' ') && (encode_mode[i] == 'X')) { } else if ((source[i] == '.' || source[i] == ',') && source[i + 1] == ' ' && encode_mode[i] == 'X') {
count = az_count_doubles(source, i, src_len); count = az_count_doubles(source, i, length);
next_mode = az_get_next_mode(encode_mode, src_len, i); next_mode = az_get_next_mode(encode_mode, length, i);
if (current_mode == 'U') { if (current_mode == 'U') {
if ((next_mode == 'D') && (count <= 5)) { if (next_mode == 'D' && count <= 5) {
memset(encode_mode + i, 'D', 2 * count); memset(encode_mode + i, 'D', 2 * count);
} }
} else if (current_mode == 'L') { } else if (current_mode == 'L') {
if ((next_mode == 'D') && (count <= 4)) { if (next_mode == 'D' && count <= 4) {
memset(encode_mode + i, 'D', 2 * count); memset(encode_mode + i, 'D', 2 * count);
} }
} else if (current_mode == 'M') { } else if (current_mode == 'M') {
if ((next_mode == 'D') && (count == 1)) { if (next_mode == 'D' && count == 1) {
encode_mode[i] = 'D'; encode_mode[i] = 'D';
encode_mode[i + 1] = 'D'; encode_mode[i + 1] = 'D';
} }
} else if (current_mode == '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); 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); 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]; current_mode = encode_mode[i];
} }
} }
if (debug_print) { if (debug_print) {
fputs("First Pass:\n", stdout); 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 */ /* Reduce two letter combinations to one codeword marked as [abcd] in Punct mode */
i = 0; i = 0;
j = 0; j = 0;
while (i < src_len) { while (i < length) {
reduced_encode_mode[j] = encode_mode[i]; reduced_encode_mode[j] = encode_mode[i];
if (i + 1 < src_len) { if (i + 1 < length) {
if ((source[i] == 13) && (source[i + 1] == 10)) { /* CR LF */ if (source[i] == 13 && source[i + 1] == 10) { /* CR LF */
reduced_source[j] = 'a'; reduced_source[j] = 'a';
i += 2; 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'; reduced_source[j] = 'b';
i += 2; 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'; reduced_source[j] = 'c';
i += 2; i += 2;
} else if ((source[i] == ':') && (source[i + 1] == ' ')) { } else if (source[i] == ':' && source[i + 1] == ' ') {
reduced_source[j] = 'd'; reduced_source[j] = 'd';
i += 2; i += 2;
} else { } 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); count = az_count_chr(reduced_source, i, reduced_length, 13);
next_mode = az_get_next_mode(reduced_encode_mode, reduced_length, i); 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'; 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'; 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'; reduced_encode_mode[i] = 'P';
} }
if (current_mode == 'D') { if (current_mode == 'D') {
if (((next_mode == 'E') || (next_mode == 'U') || (next_mode == 'D') || (next_mode == 'B')) if ((next_mode == 'E' || next_mode == 'U' || next_mode == 'D' || next_mode == 'B') && count <= 2) {
&& (count <= 2)) {
memset(reduced_encode_mode + i, 'P', count); 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'; 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 */ /* 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); count = az_count_dotcomma(reduced_source, i, reduced_length);
next_mode = az_get_next_mode(reduced_encode_mode, reduced_length, i); next_mode = az_get_next_mode(reduced_encode_mode, reduced_length, i);
if (current_mode == 'U') { if (current_mode == 'U') {
if (((next_mode == 'U') || (next_mode == 'L') || (next_mode == 'M') || (next_mode == 'B')) if ((next_mode == 'U' || next_mode == 'L' || next_mode == 'M' || next_mode == 'B') && count == 1) {
&& (count == 1)) {
reduced_encode_mode[i] = 'P'; reduced_encode_mode[i] = 'P';
} }
} else if (current_mode == 'L') { } else if (current_mode == 'L') {
if ((next_mode == 'L') && (count <= 2)) { if (next_mode == 'L' && count <= 2) {
memset(reduced_encode_mode + i, 'P', count); 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'; reduced_encode_mode[i] = 'P';
} }
} else if (current_mode == 'M') { } else if (current_mode == 'M') {
if (((next_mode == 'E') || (next_mode == 'U') || (next_mode == 'L') || (next_mode == 'M')) if ((next_mode == 'E' || next_mode == 'U' || next_mode == 'L' || next_mode == 'M') && count <= 4) {
&& (count <= 4)) {
memset(reduced_encode_mode + i, 'P', count); 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); 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); 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); next_mode = az_get_next_mode(reduced_encode_mode, reduced_length, i);
if (current_mode == 'U') { if (current_mode == 'U') {
if ((next_mode == 'E') && (count <= 5)) { if (next_mode == 'E' && count <= 5) {
memset(reduced_encode_mode + i, 'U', count); memset(reduced_encode_mode + i, 'U', count);
} else if (((next_mode == 'U') || (next_mode == 'L') || (next_mode == 'M') || (next_mode == 'P') } else if ((next_mode == 'U' || next_mode == 'L' || next_mode == 'M' || next_mode == 'P'
|| (next_mode == 'B')) && (count <= 9)) { || next_mode == 'B') && count <= 9) {
memset(reduced_encode_mode + i, 'U', count); memset(reduced_encode_mode + i, 'U', count);
} }
} else if (current_mode == 'L') { } else if (current_mode == 'L') {
if ((next_mode == 'E') && (count <= 5)) { if (next_mode == 'E' && count <= 5) {
memset(reduced_encode_mode + i, 'L', count); 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'; 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); 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); memset(reduced_encode_mode + i, 'L', count);
} }
} else if (current_mode == 'M') { } 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); 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); 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); memset(reduced_encode_mode + i, 'M', count);
} }
} else if (current_mode == 'P') { } else if (current_mode == 'P') {
if ((next_mode == 'E') && (count <= 5)) { if (next_mode == 'E' && count <= 5) {
memset(reduced_encode_mode + i, 'U', count); memset(reduced_encode_mode + i, 'U', count);
} else if (((next_mode == 'U') || (next_mode == 'L') || (next_mode == 'M') || (next_mode == 'P') } else if ((next_mode == 'U' || next_mode == 'L' || next_mode == 'M' || next_mode == 'P'
|| (next_mode == 'B')) && (count <= 9)) { || next_mode == 'B') && count <= 9) {
memset(reduced_encode_mode + i, 'U', count); 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) { if (reduced_encode_mode[i] != current_mode) {
for (count = 0; ((i + count) < reduced_length) for (count = 0; i + count < reduced_length && reduced_encode_mode[i + count] == reduced_encode_mode[i];
&& (reduced_encode_mode[i + count] == reduced_encode_mode[i]); count++); count++);
next_mode = az_get_next_mode(reduced_encode_mode, reduced_length, i); next_mode = az_get_next_mode(reduced_encode_mode, reduced_length, i);
if (reduced_encode_mode[i] == 'P') { 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); 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); 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'; 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'; 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); 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); 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); memset(reduced_encode_mode + i, 'p', count);
} }
} else if (reduced_encode_mode[i] == 'U') { } 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); memset(reduced_encode_mode + i, 'u', count);
} else if ((current_mode == 'L') && ((next_mode == 'E') || (next_mode == 'D') || (next_mode == 'B') } else if (current_mode == 'L' && (next_mode == 'E' || next_mode == 'D' || next_mode == 'B'
|| (next_mode == 'P')) && (count == 1)) { || next_mode == 'P') && count == 1) {
reduced_encode_mode[i] = 'u'; 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'; 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); 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]; 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) { 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, initial_mode == 'D' ? 4 : 5, binary_string, bp); /* P/S */
bp = z_bin_append_posn(0, 5, binary_string, bp); /* FLG(n) */ 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(1, 3, binary_string, bp); /* FLG(1) */
bp = z_bin_append_posn(2 + eci, 4, binary_string, bp); bp = z_bin_append_posn(2 + eci, 4, binary_string, bp);
} else if (eci <= 99) { } 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 */ /* Byte mode - process full block here */
if (reduced_encode_mode[i] == 'B') { if (reduced_encode_mode[i] == 'B') {
int big_batch = 0; 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 */ if (count > 2047 + 2078) { /* Can't be more than 19968 / 8 = 2496 */
return 0; return 0;
@@ -614,12 +602,12 @@ static int aztec_text_process(const unsigned char source[], int src_len, int bp,
continue; 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]; 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 (reduced_source[i] == ' ') {
if (!(bp = az_bin_append_posn(1, 5, binary_string, bp))) return 0; /* SP */ if (!(bp = az_bin_append_posn(1, 5, binary_string, bp))) return 0; /* SP */
} else { } else {
@@ -639,7 +627,7 @@ static int aztec_text_process(const unsigned char source[], int src_len, int bp,
} else { } else {
if (!(bp = az_bin_append_posn(AztecSymbolChar[reduced_source[i]], 5, binary_string, bp))) return 0; 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 (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, 5, binary_string, bp))) return 0; /* FLG(n) */
if (!(bp = az_bin_append_posn(0, 3, binary_string, bp))) return 0; /* FLG(0) = FNC1 */ 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..." /* 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..." */ "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 */ /* Codeword of B-1 '0's or B-1 '1's */
if (j > data_maxsize) { if (j > data_maxsize) {
return 0; /* Fail */ 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 each level of error correction work out the smallest symbol which the data will fit in */
for (i = compact_loop_start; i > 0; i--) { 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; layers = i;
compact = 1; compact = 1;
data_maxsize = AztecCompactDataSizes[ecc_level - 1][i - 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) { if (!compact) {
for (i = 32; i > 0; i--) { 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; layers = i;
compact = 0; compact = 0;
data_maxsize = AztecDataSizes[ecc_level - 1][i - 1]; 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 */ symbol->option_2 = compact ? layers : layers + 4; /* Feedback options */
} else { /* The size of the symbol has been specified by the user */ } 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)", return z_errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 510, "Version '%d' out of range (1 to 36)",
symbol->option_2); symbol->option_2);
} }
@@ -1105,7 +1093,7 @@ INTERNAL int zint_aztec(struct zint_symbol *symbol, struct zint_seg segs[], cons
fputc('\n', stdout); fputc('\n', stdout);
} }
if (reader_init && (layers > 22)) { if (reader_init && layers > 22) {
return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 506, return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 506,
"Input too long for Reader Initialisation, requires %d layers (maximum 22)", layers); "Input too long for Reader Initialisation, requires %d layers (maximum 22)", layers);
} }
+1 -1
View File
@@ -192,7 +192,7 @@ INTERNAL int zint_channel(struct zint_symbol *symbol, unsigned char source[], in
} }
target_value = z_to_int(source, length); 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; channels = 0;
} else { } else {
channels = symbol->option_2; channels = symbol->option_2;
+3 -4
View File
@@ -71,12 +71,11 @@ INTERNAL int zint_codabar(struct zint_symbol *symbol, unsigned char source[], in
z_to_upper(source, length); z_to_upper(source, length);
/* Codabar must begin and end with the characters A, B, C or D */ /* Codabar must begin and end with the characters A, B, C or D */
if ((source[0] != 'A') && (source[0] != 'B') && (source[0] != 'C') if (source[0] != 'A' && source[0] != 'B' && source[0] != 'C' && source[0] != 'D') {
&& (source[0] != 'D')) {
return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 358, "Does not begin with \"A\", \"B\", \"C\" or \"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') && if (source[length - 1] != 'A' && source[length - 1] != 'B' && source[length - 1] != 'C'
(source[length - 1] != 'C') && (source[length - 1] != 'D')) { && source[length - 1] != 'D') {
return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 359, "Does not end with \"A\", \"B\", \"C\" or \"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))) { if ((i = z_not_sane_lookup(CALCIUM, sizeof(CALCIUM) - 1, source, length, posns))) {
+4 -4
View File
@@ -129,15 +129,15 @@ INTERNAL int zint_code39(struct zint_symbol *symbol, unsigned char source[], int
int error_number = 0; int error_number = 0;
const int raw_text = symbol->output_options & BARCODE_RAW_TEXT; 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; symbol->option_2 = 0;
} }
/* LOGMARS MIL-STD-1189 Rev. B https://apps.dtic.mil/dtic/tr/fulltext/u2/a473534.pdf */ /* 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); 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 */ /* 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 */ /* 70 less '+' and check */
return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 319, "Input length %d too long (maximum 68)", length - 2); 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 */ } 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); memcpy(d, C39Table[43], 9);
d += 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 */ /* LOGMARS and HIBC use wider 'wide' bars than normal Code 39 */
counter = d - dest; counter = d - dest;
for (i = 0; i < counter; i++) { for (i = 0; i < counter; i++) {
+9 -9
View File
@@ -71,7 +71,7 @@ static int c16k_parunmodd(const unsigned char llyth, const int check_fnc1) {
if (llyth <= 31) { if (llyth <= 31) {
modd = check_fnc1 && llyth == '\x1D' ? C16K_ABORC : C16K_SHIFTA; modd = check_fnc1 && llyth == '\x1D' ? C16K_ABORC : C16K_SHIFTA;
} else if ((llyth >= 48) && (llyth <= 57)) { } else if (llyth >= 48 && llyth <= 57) {
modd = C16K_ABORC; modd = C16K_ABORC;
} else if (llyth <= 95) { } else if (llyth <= 95) {
modd = C16K_AORB; 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 (i == 0) { /* First block */
if (current == C16K_ABORC) { if (current == C16K_ABORC) {
if ((indexliste == 1) && (length == 2)) { if (indexliste == 1 && length == 2) {
/* Rule 1a */ /* Rule 1a */
list[1][i] = C16K_LATCHC; list[1][i] = C16K_LATCHC;
current = C16K_LATCHC; current = C16K_LATCHC;
@@ -362,7 +362,7 @@ INTERNAL int zint_code16k(struct zint_symbol *symbol, unsigned char source[], in
do { do {
list[1][indexliste] = mode; list[1][indexliste] = mode;
while ((list[1][indexliste] == mode) && (indexchaine < length)) { while (list[1][indexliste] == mode && indexchaine < length) {
list[0][indexliste]++; list[0][indexliste]++;
indexchaine++; indexchaine++;
if (indexchaine == length) { if (indexchaine == length) {
@@ -393,7 +393,7 @@ INTERNAL int zint_code16k(struct zint_symbol *symbol, unsigned char source[], in
} }
if (m == 2) { if (m == 2) {
m = 5; 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; m = 6;
} }
values[1] = 96; /* FNC3 */ 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; case 'C': m = 4; break;
} }
} else { } else {
if ((set[0] == 'B') && (set[1] == 'C')) { if (set[0] == 'B' && set[1] == 'C') {
m = fset[0] == 'f' ? 6 : 5; 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; 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 */ /* TODO: make use of extra (non-CODE128) shifts: 1SB, 2SA/B/C, 3SB/C */
do { do {
if ((read != 0) && (set[read] != current_set)) { if (read != 0 && set[read] != current_set) {
/* Latch different code set */ /* Latch different code set */
switch (set[read]) { switch (set[read]) {
case 'A': 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 */ /* Insert shift character */
values[bar_characters++] = 98; values[bar_characters++] = 98;
} }
@@ -492,7 +492,7 @@ INTERNAL int zint_code16k(struct zint_symbol *symbol, unsigned char source[], in
if (pads_needed == 5) { if (pads_needed == 5) {
pads_needed = 0; pads_needed = 0;
} }
if ((bar_characters + pads_needed) < 8) { if (bar_characters + pads_needed < 8) {
pads_needed += 8 - (bar_characters + pads_needed); pads_needed += 8 - (bar_characters + pads_needed);
} }
+5 -5
View File
@@ -97,7 +97,7 @@ INTERNAL int zint_code49(struct zint_symbol *symbol, unsigned char source[], int
block_remain = j % 5; block_remain = j % 5;
for (c = 0; c < block_count; c++) { 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) */ /* Rule (d) */
block_value = 100000 + z_to_int(ZCUCP(intermediate + i), 4); 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; rows = 0;
do { do {
for (i = 0; i < 7; i++) { 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]; c_grid[rows][i] = codewords[(rows * 7) + i];
} else { } else {
c_grid[rows][i] = 48; /* Pad */ c_grid[rows][i] = 48; /* Pad */
@@ -215,9 +215,9 @@ INTERNAL int zint_code49(struct zint_symbol *symbol, unsigned char source[], int
} }
} }
rows++; 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 */ /* Add a row */
for (i = 0; i < 7; i++) { for (i = 0; i < 7; i++) {
c_grid[rows][i] = 48; /* Pad */ 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 = 0;
bp = z_bin_append_posn(2, 2, pattern, bp); /* Start character "10" */ bp = z_bin_append_posn(2, 2, pattern, bp); /* Start character "10" */
for (j = 0; j < 4; j++) { for (j = 0; j < 4; j++) {
if (i != (rows - 1)) { if (i != rows - 1) {
if (c49_table4[i][j] == 'E') { if (c49_table4[i][j] == 'E') {
/* Even Parity */ /* Even Parity */
bp = z_bin_append_posn(c49_even_bitpattern[w_grid[i][j]], 16, pattern, bp); bp = z_bin_append_posn(c49_even_bitpattern[w_grid[i][j]], 16, pattern, bp);
+5 -5
View File
@@ -39,9 +39,9 @@
INTERNAL int z_ctoi(const char source) { INTERNAL int z_ctoi(const char source) {
if (z_isdigit(source)) if (z_isdigit(source))
return (source - '0'); return (source - '0');
if ((source >= 'A') && (source <= 'F')) if (source >= 'A' && source <= 'F')
return (source - 'A' + 10); return (source - 'A' + 10);
if ((source >= 'a') && (source <= 'f')) if (source >= 'a' && source <= 'f')
return (source - 'a' + 10); return (source - 'a' + 10);
return -1; return -1;
} }
@@ -662,7 +662,7 @@ INTERNAL int z_is_fixed_ratio(const int symbology) {
/* Whether next two characters are digits */ /* Whether next two characters are digits */
INTERNAL int z_is_twodigits(const unsigned char source[], const int length, const int position) { 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; 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]; 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]; *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) { if (state != 0) {
return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 240, "Corrupt Unicode data"); 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, return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 242,
"Unicode sequences of more than 3 bytes not supported"); "Unicode sequences of more than 3 bytes not supported");
} }
+2 -2
View File
@@ -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; 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->width += top_shift;
} }
symbol->rows += linear->rows; symbol->rows += linear->rows;
+15 -15
View File
@@ -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; cnt_1 = b256_count + DM_MULT_1;
if (cnt_1 <= ascii_count || (cnt_1 < edf_count && cnt_1 < text_count && cnt_1 < x12_count 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); if (debug_print) fputs("BAS->", stdout);
return DM_BASE256; /* step (r)(2) */ 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) { 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] << 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]); target[tp++] = (unsigned char) ((process_buffer[i + 2] & 0x03) << 6 | process_buffer[i + 3]);
if (debug_print) { if (debug_print) {
printf("[%d %d %d %d (%d %d %d)] ", process_buffer[i], process_buffer[i + 1], process_buffer[i + 2], 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 (empty) {
if (process_p == 3) { 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] << 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
| (process_buffer[i + 2] & 0x3c) >> 2); | (process_buffer[i + 2] & 0x3C) >> 2);
target[tp++] = (unsigned char) ((process_buffer[i + 2] & 0x03) << 6); target[tp++] = (unsigned char) ((process_buffer[i + 2] & 0x03) << 6);
if (debug_print) { if (debug_print) {
printf("[%d %d %d (%d %d %d)] ", process_buffer[i], process_buffer[i + 1], process_buffer[i + 2], 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) { } 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] << 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) { if (debug_print) {
printf("[%d %d (%d %d)] ", process_buffer[i], process_buffer[i + 1], target[tp - 2], printf("[%d %d (%d %d)] ", process_buffer[i], process_buffer[i + 1], target[tp - 2],
target[tp - 1]); 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) { static int dm_get_symbolsize(struct zint_symbol *symbol, const int minimum) {
int i; 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]; return dm_intsymbol[symbol->option_2 - 1];
} }
if (minimum > 1304) { 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); tp = dm_update_b256_field_length(target, tp, *p_b256_start);
/* B.2.1 255-state randomising algorithm */ /* B.2.1 255-state randomising algorithm */
for (i = *p_b256_start; i < tp; i++) { 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); target[i] = (unsigned char) ((target[i] + prn) & 0xFF);
} }
break; 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); tp = dm_update_b256_field_length(target, tp, *p_b256_start);
/* B.2.1 255-state randomising algorithm */ /* B.2.1 255-state randomising algorithm */
for (i = *p_b256_start; i < tp; i++) { 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); 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()` */ /* 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) { } else if (current_mode == DM_X12) {
if (debug_print) fputs("X12 ", stdout); if (debug_print) fputs("X12 ", stdout);
if ((symbols_left == 1) && (process_p == 1)) { if (symbols_left == 1 && process_p == 1) {
/* Unlatch not required! */ /* Unlatch not required! */
target[tp++] = source[length - 1] + 1; target[tp++] = source[length - 1] + 1;
if (debug_print) printf("A%02X ", target[tp - 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 */ /* B.2.1 255-state randomising algorithm */
for (i = b256_start; i < tp; i++) { 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); 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 */ /* add pad bits */
static void dm_add_tail(unsigned char target[], int tp, const int tail_length) { static void dm_add_tail(unsigned char target[], int tp, const int tail_length) {
int i, prn, temp; int i;
target[tp++] = 129; /* Pad */ target[tp++] = 129; /* Pad */
for (i = 1; i < tail_length; i++) { for (i = 1; i < tail_length; i++) {
/* B.1.1 253-state randomising algorithm */ /* B.1.1 253-state randomising algorithm */
prn = ((149 * (tp + 1)) % 253) + 1; const int prn = (149 * (tp + 1)) % 253 + 1;
temp = 129 + prn; const int temp = 129 + prn;
if (temp <= 254) { if (temp <= 254) {
target[tp++] = (unsigned char) (temp); target[tp++] = (unsigned char) temp;
} else { } else {
target[tp++] = (unsigned char) (temp - 254); 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); symbolsize = dm_get_symbolsize(symbol, binlen);
if (binlen > dm_matrixbytes[symbolsize]) { 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) */ /* The symbol size was given by --ver (option_2) */
return ZEXT z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 522, return ZEXT z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 522,
"Input too long for Version %1$d, requires %2$d codewords (maximum %3$d)", "Input too long for Version %1$d, requires %2$d codewords (maximum %3$d)",
+22 -25
View File
@@ -453,8 +453,8 @@ static int dc_ahead_b(const unsigned char source[], const int length, const int
int count = 0; int count = 0;
int i, incr; int i, incr;
for (i = position; i < length && (incr = dc_datum_b(source, length, i)) for (i = position; i < length && (incr = dc_datum_b(source, length, i)) && dc_try_c(source, length, i) < 2;
&& dc_try_c(source, length, i) < 2; i += incr) { i += incr) {
count++; 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 */ } else if (length > 5) { /* Note assuming macro headers don't straddle segments */
/* Step C1 */ /* Step C1 */
if (source[0] == '[' && source[1] == ')' && source[2] == '>' && source[3] == 30 /*RS*/ && last_EOT) { 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')) const int format_050612 = (source[4] == '0' && (source[5] == '5' || source[5] == '6'))
|| (source[4] == '1' && source[5] == '2'); || (source[4] == '1' && source[5] == '2');
inside_macro = 0; inside_macro = 0;
if (length > 6 && format_050612 && source[6] == 29 /*GS*/ && last_RSEOT) { if (length > 6 && format_050612 && source[6] == 29 /*GS*/ && last_RSEOT) {
if (source[5] == '5') { if (source[5] == '5') {
@@ -613,7 +613,7 @@ static int dc_encode_message(struct zint_symbol *symbol, const unsigned char sou
while (position < length) { while (position < length) {
/* Step A */ /* 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 */ /* inside_macro only gets set to 97, 98 or 99 if the last two characters are RS/EOT */
position += 2; position += 2;
if (debug_print) fputs("A ", stdout); 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 */ /* 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 */ /* inside_macro only gets set to 100 if the last character is EOT */
position++; position++;
if (debug_print) fputs("B ", stdout); 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)) { if (dc_binary(source, length, position)) {
/* z_cnt_digits(position + 1) > 0 */ /* z_cnt_digits(position + 1) > 0 */
if (position + 1 < length && z_isdigit(source[position + 1])) { 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++] = 110; /* Upper Shift A */
codeword_array[ap++] = source[position] - 128 + 64; codeword_array[ap++] = source[position] - 128 + 64;
} else { } 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)) { if (dc_datum_b(source, length, position)) {
int done = 0; int done = 0;
if ((source[position] >= 32) && (source[position] <= 127)) { if (source[position] >= 32 && source[position] <= 127) {
codeword_array[ap++] = source[position] - 32; codeword_array[ap++] = source[position] - 32;
done = 1; done = 1;
@@ -772,7 +772,7 @@ static int dc_encode_message(struct zint_symbol *symbol, const unsigned char sou
/* Step D3 */ /* Step D3 */
if (dc_binary(source, length, position)) { if (dc_binary(source, length, position)) {
if (dc_datum_b(source, length, position + 1)) { 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++] = 110; /* Bin Shift A */
codeword_array[ap++] = source[position] - 128 + 64; codeword_array[ap++] = source[position] - 128 + 64;
} else { } else {
@@ -845,7 +845,7 @@ static int dc_encode_message(struct zint_symbol *symbol, const unsigned char sou
/* Step E3 */ /* Step E3 */
if (dc_binary(source, length, position)) { if (dc_binary(source, length, position)) {
if (dc_datum_a(source, length, position + 1)) { 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++] = 110; /* Bin Shift A */
codeword_array[ap++] = source[position] - 128 + 64; codeword_array[ap++] = source[position] - 128 + 64;
} else { } 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) { static int dc_is_corner(const int column, const int row, const int width, const int height) {
/* Top Left */ /* Top Left */
if ((column == 0) && (row == 0)) { if (column == 0 && row == 0) {
return 1; return 1;
} }
/* Top Right */ /* Top Right */
if (height & 1) { if (height & 1) {
if (((column == width - 2) && (row == 0)) if ((column == width - 2 && row == 0) || (column == width - 1 && row == 1)) {
|| ((column == width - 1) && (row == 1))) {
return 1; return 1;
} }
} else { } else {
if ((column == width - 1) && (row == 0)) { if (column == width - 1 && row == 0) {
return 1; return 1;
} }
} }
/* Bottom Left */ /* Bottom Left */
if (height & 1) { if (height & 1) {
if ((column == 0) && (row == height - 1)) { if (column == 0 && row == height - 1) {
return 1; return 1;
} }
} else { } else {
if (((column == 0) && (row == height - 2)) if ((column == 0 && row == height - 2) || (column == 1 && row == height - 1)) {
|| ((column == 1) && (row == height - 1))) {
return 1; return 1;
} }
} }
/* Bottom Right */ /* Bottom Right */
if (((column == width - 2) && (row == height - 1)) if ((column == width - 2 && row == height - 1) || (column == width - 1 && row == height - 2)) {
|| ((column == width - 1) && (row == height - 2))) {
return 1; return 1;
} }
@@ -1296,26 +1293,26 @@ INTERNAL int zint_dotcode(struct zint_symbol *symbol, struct zint_seg segs[], co
width = (int) w; width = (int) w;
if (((width + height) & 1) == 1) { if (((width + height) & 1) == 1) {
if ((width * height) < min_area) { if (width * height < min_area) {
width++; width++;
height++; height++;
} }
} else { } else {
if ((h * width) < (w * height)) { if (h * width < w * height) {
width++; width++;
if ((width * height) < min_area) { if (width * height < min_area) {
width--; width--;
height++; height++;
if ((width * height) < min_area) { if (width * height < min_area) {
width += 2; width += 2;
} }
} }
} else { } else {
height++; height++;
if ((width * height) < min_area) { if (width * height < min_area) {
width++; width++;
height--; height--;
if ((width * height) < min_area) { if (width * height < min_area) {
height += 2; height += 2;
} }
} }
+3 -6
View File
@@ -261,11 +261,10 @@ static int fm_vprintf(struct filemem *restrict const fmp, const char *fmt, va_li
#endif #endif
va_copy(cpy, ap); va_copy(cpy, ap);
/* The clang-tidy warning is a bug https://github.com/llvm/llvm-project/issues/40656 */
#ifdef FM_NO_VSNPRINTF #ifdef FM_NO_VSNPRINTF
size = vfprintf(fmp->fp_null, fmt, cpy); /* NOLINT(clang-analyzer-valist.Uninitialized) */ size = vfprintf(fmp->fp_null, fmt, cpy);
#else #else
size = vsnprintf(NULL, 0, fmt, cpy); /* NOLINT(clang-analyzer-valist.Uninitialized) */ size = vsnprintf(NULL, 0, fmt, cpy);
#endif #endif
va_end(cpy); 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 #ifdef FM_NO_VSNPRINTF
/* NOLINTNEXTLINE(clang-analyzer-valist.Uninitialized) - see above */
check = vsprintf((char *) fmp->mem + fmp->mempos, fmt, ap); check = vsprintf((char *) fmp->mem + fmp->mempos, fmt, ap);
#else #else
/* NOLINTNEXTLINE(clang-analyzer-valist.Uninitialized) - see above */
check = vsnprintf((char *) fmp->mem + fmp->mempos, size + 1, fmt, ap); check = vsnprintf((char *) fmp->mem + fmp->mempos, size + 1, fmt, ap);
#endif #endif
@@ -309,7 +306,7 @@ INTERNAL int zint_fm_printf(struct filemem *restrict const fmp, const char *fmt,
return ret; return ret;
} }
va_start(ap, fmt); 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); va_end(ap);
return ret ? 1 : fm_seterr(fmp, errno); return ret ? 1 : fm_seterr(fmp, errno);
} }
+23 -24
View File
@@ -456,22 +456,22 @@ static int gm_encode(unsigned int ddata[], const int length, char binary[], cons
switch (current_mode) { switch (current_mode) {
case GM_CHINESE: case GM_CHINESE:
done = 0; done = 0;
if (ddata[sp] > 0xff) { if (ddata[sp] > 0xFF) {
/* GB2312 character */ /* GB2312 character */
c1 = (ddata[sp] & 0xff00) >> 8; c1 = (ddata[sp] & 0xFF00) >> 8;
c2 = ddata[sp] & 0xff; c2 = ddata[sp] & 0xFF;
if ((c1 >= 0xa1) && (c1 <= 0xa9)) { if (c1 >= 0xA1 && c1 <= 0xA9) {
glyph = (0x60 * (c1 - 0xa1)) + (c2 - 0xa0); glyph = 0x60 * (c1 - 0xA1) + (c2 - 0xA0);
} else if ((c1 >= 0xb0) && (c1 <= 0xf7)) { } else if (c1 >= 0xB0 && c1 <= 0xF7) {
glyph = (0x60 * (c1 - 0xb0 + 9)) + (c2 - 0xa0); glyph = 0x60 * (c1 - 0xB0 + 9) + (c2 - 0xA0);
} }
done = 1; /* GB 2312 always within above ranges */ 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 */ /* Note not using the unallocated glyphs 7776 to 8191 mentioned in AIMD014 section 6.3.1.2 */
} }
if (!(done)) { if (!done) {
if (sp != (length - 1)) { if (sp != length - 1) {
if ((ddata[sp] == 13) && (ddata[sp + 1] == 10)) { if (ddata[sp] == 13 && ddata[sp + 1] == 10) {
/* End of Line */ /* End of Line */
glyph = 7776; glyph = 7776;
sp++; sp++;
@@ -479,8 +479,8 @@ static int gm_encode(unsigned int ddata[], const int length, char binary[], cons
} }
} }
} }
if (!(done)) { if (!done) {
if (sp != (length - 1)) { if (sp != length - 1) {
if (z_isdigit(ddata[sp]) && z_isdigit(ddata[sp + 1])) { if (z_isdigit(ddata[sp]) && z_isdigit(ddata[sp + 1])) {
/* Two digits */ /* Two digits */
glyph = 8033 + (10 * (ddata[sp] - '0')) + (ddata[sp + 1] - '0'); 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 */ /* Byte value */
glyph = 7777 + ddata[sp]; glyph = 7777 + ddata[sp];
} }
@@ -527,7 +527,7 @@ static int gm_encode(unsigned int ddata[], const int length, char binary[], cons
} }
punt = ddata[sp]; punt = ddata[sp];
ppos = p; 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) {
/* <end of line> */ /* <end of line> */
if (ppos != -1) { if (ppos != -1) {
break; break;
@@ -539,7 +539,7 @@ static int gm_encode(unsigned int ddata[], const int length, char binary[], cons
break; break;
} }
sp++; sp++;
} while ((p < 3) && (sp < length) && mode[sp] == GM_NUMBER); } while (p < 3 && sp < length && mode[sp] == GM_NUMBER);
if (ppos != -1) { if (ppos != -1) {
switch (punt) { 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; data[data_posn] = 0x00;
for (i = (data_posn + 1); i < data_cw; i++) { for (i = (data_posn + 1); i < data_cw; i++) {
if (i & 1) { if (i & 1) {
data[i] = 0x7e; data[i] = 0x7E;
} else { } else {
data[i] = 0x00; data[i] = 0x00;
} }
@@ -1097,7 +1097,7 @@ INTERNAL int zint_gridmatrix(struct zint_symbol *symbol, struct zint_seg segs[],
} }
layers = auto_layers; layers = auto_layers;
if ((symbol->option_2 >= 1) && (symbol->option_2 <= 13)) { if (symbol->option_2 >= 1 && symbol->option_2 <= 13) {
input_latch = 1; input_latch = 1;
if (symbol->option_2 >= min_layers) { if (symbol->option_2 >= min_layers) {
layers = symbol->option_2; layers = symbol->option_2;
@@ -1111,7 +1111,7 @@ INTERNAL int zint_gridmatrix(struct zint_symbol *symbol, struct zint_seg segs[],
auto_ecc_level = 3; auto_ecc_level = 3;
if (layers == 1) { if (layers == 1) {
auto_ecc_level = 5; auto_ecc_level = 5;
} else if ((layers == 2) || (layers == 3)) { } else if (layers == 2 || layers == 3) {
auto_ecc_level = 4; auto_ecc_level = 4;
} }
ecc_level = auto_ecc_level; 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; 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) { if (symbol->option_1 >= min_ecc_level) {
ecc_level = symbol->option_1; ecc_level = symbol->option_1;
} else { } else {
ecc_level = min_ecc_level; 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 layers user-specified (option_2), try reducing ECC level first */
if (input_latch && ecc_level > min_ecc_level) { if (input_latch && ecc_level > min_ecc_level) {
do { do {
ecc_level--; ecc_level--;
} while ((data_cw > gm_data_codewords[(5 * (layers - 1)) + (ecc_level - 1)]) } while (data_cw > gm_data_codewords[5 * (layers - 1) + (ecc_level - 1)] && ecc_level > min_ecc_level);
&& (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++; layers++;
} }
/* ECC min level 1 for layers > 2 */ /* 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--; ecc_level--;
} }
} }
+2 -2
View File
@@ -1767,8 +1767,8 @@ INTERNAL int zint_gs1_verify(struct zint_symbol *symbol, unsigned char source[],
data_location[i] = ai_location[i] + 3; data_location[i] = ai_location[i] + 3;
} }
data_length[i] = 0; data_length[i] = 0;
while ((data_location[i] + data_length[i] < length) while (data_location[i] + data_length[i] < length
&& (source[data_location[i] + data_length[i]] != obracket)) { && source[data_location[i] + data_length[i]] != obracket) {
data_length[i]++; data_length[i]++;
} }
if (data_length[i] == 0) { if (data_length[i] == 0) {
+58 -58
View File
@@ -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 */ /* 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 */ /* 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; est_binlen += 4;
} }
if (mode[i] == 'b') { /* Byte mode has byte count (and no terminator) */ 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; byte = glyph >> 8;
if ((byte >= 0xb0) && (byte <= 0xd7)) { if (byte >= 0xB0 && byte <= 0xD7) {
byte = glyph & 0xff; byte = glyph & 0xFF;
if ((byte >= 0xa1) && (byte <= 0xfe)) { if (byte >= 0xA1 && byte <= 0xFE) {
return 1; return 1;
} }
} else if ((byte >= 0xa1) && (byte <= 0xa3)) { } else if (byte >= 0xA1 && byte <= 0xA3) {
byte = glyph & 0xff; byte = glyph & 0xFF;
if ((byte >= 0xa1) && (byte <= 0xfe)) { if (byte >= 0xA1 && byte <= 0xFE) {
return 1; return 1;
} }
} else if ((glyph >= 0xa8a1) && (glyph <= 0xa8c0)) { } else if (glyph >= 0xA8A1 && glyph <= 0xA8C0) {
return 1; return 1;
} }
@@ -199,9 +199,9 @@ static int hx_isRegion2(const unsigned int glyph) {
byte = glyph >> 8; byte = glyph >> 8;
if ((byte >= 0xd8) && (byte <= 0xf7)) { if (byte >= 0xD8 && byte <= 0xF7) {
byte = glyph & 0xff; byte = glyph & 0xFF;
if ((byte >= 0xa1) && (byte <= 0xfe)) { if (byte >= 0xA1 && byte <= 0xFE) {
return 1; return 1;
} }
} }
@@ -214,12 +214,12 @@ static int hx_isDoubleByte(const unsigned int glyph) {
byte = glyph >> 8; byte = glyph >> 8;
if ((byte >= 0x81) && (byte <= 0xfe)) { if (byte >= 0x81 && byte <= 0xFE) {
byte = glyph & 0xff; byte = glyph & 0xFF;
if ((byte >= 0x40) && (byte <= 0x7e)) { if (byte >= 0x40 && byte <= 0x7E) {
return 1; return 1;
} }
if ((byte >= 0x80) && (byte <= 0xfe)) { if (byte >= 0x80 && byte <= 0xFE) {
return 1; return 1;
} }
} }
@@ -232,13 +232,13 @@ static int hx_isFourByte(const unsigned int glyph, const unsigned int glyph2) {
byte = glyph >> 8; byte = glyph >> 8;
if ((byte >= 0x81) && (byte <= 0xfe)) { if (byte >= 0x81 && byte <= 0xFE) {
byte = glyph & 0xff; byte = glyph & 0xFF;
if ((byte >= 0x30) && (byte <= 0x39)) { if (byte >= 0x30 && byte <= 0x39) {
byte = glyph2 >> 8; byte = glyph2 >> 8;
if ((byte >= 0x81) && (byte <= 0xfe)) { if (byte >= 0x81 && byte <= 0xFE) {
byte = glyph2 & 0xff; byte = glyph2 & 0xFF;
if ((byte >= 0x30) && (byte <= 0x39)) { if (byte >= 0x30 && byte <= 0x39) {
return 1; return 1;
} }
} }
@@ -273,19 +273,19 @@ static int hx_lookup_text2(const unsigned int input) {
return input; return input;
} }
if ((input >= ' ') && (input <= '/')) { if (input >= ' ' && input <= '/') {
return input - ' ' + 28; return input - ' ' + 28;
} }
if ((input >= ':') && (input <= '@')) { if (input >= ':' && input <= '@') {
return input - ':' + 44; return input - ':' + 44;
} }
if ((input >= '[') && (input <= 96)) { if (input >= '[' && input <= 96) {
return input - '[' + 51; return input - '[' + 51;
} }
if ((input >= '{') && (input <= 127)) { if (input >= '{' && input <= 127) {
return input - '{' + 57; return input - '{' + 57;
} }
@@ -688,22 +688,22 @@ static void hx_calculate_binary(char binary[], const char mode[], const unsigned
i = 0; i = 0;
while (i < block_length) { while (i < block_length) {
first_byte = (ddata[i + position] & 0xff00) >> 8; first_byte = (ddata[i + position] & 0xFF00) >> 8;
second_byte = ddata[i + position] & 0xff; second_byte = ddata[i + position] & 0xFF;
/* Subset 1 */ /* Subset 1 */
glyph = (0x5e * (first_byte - 0xb0)) + (second_byte - 0xa1); glyph = (0x5E * (first_byte - 0xB0)) + (second_byte - 0xA1);
/* Subset 2 */ /* Subset 2 */
if ((first_byte >= 0xa1) && (first_byte <= 0xa3)) { if (first_byte >= 0xA1 && first_byte <= 0xA3) {
if ((second_byte >= 0xa1) && (second_byte <= 0xfe)) { if (second_byte >= 0xA1 && second_byte <= 0xFE) {
glyph = (0x5e * (first_byte - 0xa1)) + (second_byte - 0xa1) + 0xeb0; glyph = (0x5E * (first_byte - 0xA1)) + (second_byte - 0xA1) + 0xEB0;
} }
} }
/* Subset 3 */ /* Subset 3 */
if ((ddata[i + position] >= 0xa8a1) && (ddata[i + position] <= 0xa8c0)) { if (ddata[i + position] >= 0xA8A1 && ddata[i + position] <= 0xA8C0) {
glyph = (second_byte - 0xa1) + 0xfca; glyph = (second_byte - 0xA1) + 0xFCA;
} }
if (debug_print) { if (debug_print) {
@@ -739,10 +739,10 @@ static void hx_calculate_binary(char binary[], const char mode[], const unsigned
i = 0; i = 0;
while (i < block_length) { while (i < block_length) {
first_byte = (ddata[i + position] & 0xff00) >> 8; first_byte = (ddata[i + position] & 0xFF00) >> 8;
second_byte = ddata[i + position] & 0xff; 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) { if (debug_print) {
printf(" %.3x[GB %.4x]", glyph, ddata[i + position]); 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; i = 0;
while (i < block_length) { while (i < block_length) {
first_byte = (ddata[i + position] & 0xff00) >> 8; first_byte = (ddata[i + position] & 0xFF00) >> 8;
second_byte = ddata[i + position] & 0xff; second_byte = ddata[i + position] & 0xFF;
if (second_byte <= 0x7e) { if (second_byte <= 0x7E) {
glyph = (0xbe * (first_byte - 0x81)) + (second_byte - 0x40); glyph = (0xBE * (first_byte - 0x81)) + (second_byte - 0x40);
} else { } else {
glyph = (0xbe * (first_byte - 0x81)) + (second_byte - 0x41); glyph = (0xBE * (first_byte - 0x81)) + (second_byte - 0x41);
} }
if (debug_print) { if (debug_print) {
@@ -813,13 +813,13 @@ static void hx_calculate_binary(char binary[], const char mode[], const unsigned
/* Mode indicator */ /* Mode indicator */
bp = z_bin_append_posn(7, 4, binary, bp); bp = z_bin_append_posn(7, 4, binary, bp);
first_byte = (ddata[i + position] & 0xff00) >> 8; first_byte = (ddata[i + position] & 0xFF00) >> 8;
second_byte = ddata[i + position] & 0xff; second_byte = ddata[i + position] & 0xFF;
third_byte = (ddata[i + position + 1] & 0xff00) >> 8; third_byte = (ddata[i + position + 1] & 0xFF00) >> 8;
fourth_byte = ddata[i + position + 1] & 0xff; fourth_byte = ddata[i + position + 1] & 0xFF;
glyph = (0x3138 * (first_byte - 0x81)) + (0x04ec * (second_byte - 0x30)) + glyph = (0x3138 * (first_byte - 0x81)) + (0x04EC * (second_byte - 0x30))
(0x0a * (third_byte - 0x81)) + (fourth_byte - 0x30); + (0x0A * (third_byte - 0x81)) + (fourth_byte - 0x30);
if (debug_print) { if (debug_print) {
printf(" %d", glyph); 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 */ /* 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) { 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 (x >= 0 && x < size) {
if ((y >= 0) && (y < size)) { if (y >= 0 && y < size) {
if (grid[(y * size) + x] == 0) { if (grid[(y * size) + x] == 0) {
grid[(y * size) + x] = value; 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 i, j, block;
int input_position = 0; int input_position = 0;
int output_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; rs_t rs;
zint_rs_init_gf(&rs, 0x163); /* x^8 + x^6 + x^5 + x + 1 = 0 */ 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++) { for (x = 0; x < size; x++) {
k = r + x; k = r + x;
if (!(grid[k] & 0xf0)) { if (!(grid[k] & 0xF0)) {
j = x + 1; j = x + 1;
i = y + 1; i = y + 1;
if (((i + j) & 1) == 0) { if (((i + j) & 1) == 0) {
mask[k] |= 0x02; mask[k] |= 0x02;
} }
if (((((i + j) % 3) + (j % 3)) & 1) == 0) { if ((((i + j) % 3 + j % 3) & 1) == 0) {
mask[k] |= 0x04; 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; 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 */ /* Do null pattern 00 separately first */
pattern = 0; pattern = 0;
for (k = 0; k < size_squared; k++) { for (k = 0; k < size_squared; k++) {
local[k] = grid[k] & 0x0f; local[k] = grid[k] & 0x0F;
} }
/* Set the Structural Info */ /* Set the Structural Info */
hx_set_function_info(local, size, version, ecc_level, pattern, 0 /*debug_print*/); 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) { if (mask[k] & bit) {
local[k] = grid[k] ^ 0x01; local[k] = grid[k] ^ 0x01;
} else { } else {
local[k] = grid[k] & 0x0f; local[k] = grid[k] & 0x0F;
} }
} }
/* Set the Structural Info */ /* 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); binary = (char *) malloc(est_binlen + 1);
if ((ecc_level <= 0) || (ecc_level >= 5)) { if (ecc_level <= 0 || ecc_level >= 5) {
ecc_level = 1; ecc_level = 1;
} }
@@ -1587,7 +1587,7 @@ INTERNAL int zint_hanxin(struct zint_symbol *symbol, struct zint_seg segs[], con
codewords); codewords);
} }
if ((symbol->option_2 < 0) || (symbol->option_2 > 84)) { if (symbol->option_2 < 0 || symbol->option_2 > 84) {
symbol->option_2 = 0; 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; version = symbol->option_2;
} }
if ((symbol->option_2 != 0) && (symbol->option_2 < version)) { if (symbol->option_2 != 0 && symbol->option_2 < version) {
free(binary); free(binary);
if (ecc_level == 1) { if (ecc_level == 1) {
return ZEXT z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 542, return ZEXT z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 542,
+2 -2
View File
@@ -418,11 +418,11 @@ INTERNAL int zint_usps_imail(struct zint_symbol *symbol, unsigned char source[],
/* Translate 4-state data pattern to symbol */ /* Translate 4-state data pattern to symbol */
read = 0; read = 0;
for (i = 0; i < 65; i++) { 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, 0, read);
} }
z_set_module(symbol, 1, 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); z_set_module(symbol, 2, read);
} }
read += 2; read += 2;
+33 -52
View File
@@ -37,6 +37,7 @@
#include <stdio.h> #include <stdio.h>
#include "common.h" #include "common.h"
#include "eci.h" #include "eci.h"
#include "filemem.h"
#include "gs1.h" #include "gs1.h"
#include "output.h" #include "output.h"
#include "zfiletypes.h" #include "zfiletypes.h"
@@ -127,8 +128,6 @@ void ZBarcode_Clear(struct zint_symbol *symbol) {
symbol->memfile_size = 0; symbol->memfile_size = 0;
z_rt_free_segs(symbol); z_rt_free_segs(symbol);
/* If there is a rendered version, ensure its memory is released */
zint_vector_free(symbol); zint_vector_free(symbol);
} }
@@ -286,77 +285,59 @@ INTERNAL int zint_test_error_tag(int error_number, struct zint_symbol *symbol, c
} }
#endif #endif
/* Output a hexadecimal representation of the rendered symbol */ /* Output a hexadecimal representation of the rendered symbol (TXT files - includes frontend "--dump" option) */
static int dump_plot(struct zint_symbol *symbol) { static int txt_hex_plot(struct zint_symbol *symbol) {
FILE *f; static const char hex[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
int i, r; struct filemem fm;
static const char hex[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; struct filemem *const fmp = &fm;
int space = 0; int r;
const int output_to_stdout = symbol->output_options & BARCODE_STDOUT;
if (output_to_stdout) { if (!zint_fm_open(fmp, symbol, "w")) {
f = stdout; return ZEXT z_errtxtf(ZINT_ERROR_FILE_ACCESS, symbol, 201, "Could not open TXT output file (%1$d: %2$s)",
} else { fmp->err, strerror(fmp->err));
#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");
}
} }
for (r = 0; r < symbol->rows; r++) { for (r = 0; r < symbol->rows; r++) {
int byt = 0; int space = 0, byt = 0;
int i;
for (i = 0; i < symbol->width; i++) { for (i = 0; i < symbol->width; i++) {
byt = byt << 1; byt <<= 1;
if (symbol->symbology == BARCODE_ULTRA) { if (symbol->symbology == BARCODE_ULTRA) {
if (z_module_colour_is_set(symbol, r, i)) { if (z_module_colour_is_set(symbol, r, i)) {
byt += 1; byt++;
} }
} else { } else {
if (z_module_is_set(symbol, r, i)) { if (z_module_is_set(symbol, r, i)) {
byt += 1; byt++;
} }
} }
if ((i + 1) % 4 == 0) { if (((i + 1) & 0x3) == 0) {
fputc(hex[byt], f); zint_fm_putc(hex[byt], fmp);
space++; space++;
byt = 0; byt = 0;
} }
if (space == 2 && i + 1 < symbol->width) { if (space == 2 && i + 1 < symbol->width) {
fputc(' ', f); zint_fm_putc(' ', fmp);
space = 0; space = 0;
} }
} }
if (symbol->width % 4 != 0) { if (symbol->width & 0x03) {
byt = byt << (4 - (symbol->width % 4)); byt <<= 4 - (symbol->width & 0x03);
fputc(hex[byt], f); zint_fm_putc(hex[byt], fmp);
} }
fputc('\n', f); zint_fm_putc('\n', fmp);
space = 0;
} }
if (ferror(f)) { if (zint_fm_error(fmp)) {
ZEXT z_errtxtf(0, symbol, 795, "Incomplete write to output (%1$d: %2$s)", errno, strerror(errno)); ZEXT z_errtxtf(0, symbol, 795, "Incomplete write of TXT output (%1$d: %2$s)", fmp->err, strerror(fmp->err));
if (!output_to_stdout) { (void) zint_fm_close(fmp, symbol);
(void) fclose(f);
}
return ZINT_ERROR_FILE_WRITE; return ZINT_ERROR_FILE_WRITE;
} }
if (output_to_stdout) { if (!zint_fm_close(fmp, symbol)) {
if (fflush(f) != 0) { return ZEXT z_errtxtf(ZINT_ERROR_FILE_WRITE, symbol, 792, "Failure on closing TXT output file (%1$d: %2$s)",
return ZEXT z_errtxtf(ZINT_ERROR_FILE_WRITE, symbol, 796, "Incomplete flush to output (%1$d: %2$s)", fmp->err, strerror(fmp->err));
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));
}
} }
return 0; return 0;
@@ -698,7 +679,7 @@ static void strip_bom(unsigned char *source, int *input_length) {
int i; int i;
/* Note if BOM is only data then not stripped */ /* 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 */ /* BOM at start of input data, strip in accordance with RFC 3629 */
for (i = 3; i <= *input_length; i++) { /* Include terminating NUL */ for (i = 3; i <= *input_length; i++) { /* Include terminating NUL */
source[i - 3] = source[i]; 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 */ /* 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, return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 246,
"Value of escape sequence '%.*s' in input out of range", "Value of escape sequence '%.*s' in input out of range",
ch == 'u' ? 6 : 8, input_string + in_posn); 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); 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) { && (symbol->input_mode & 0x07) == UNICODE_MODE) {
/* Try another ECI mode */ /* Try another ECI mode */
const int first_eci_set = zint_get_best_eci_segs(symbol, local_segs, seg_count); 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); error_number = zint_plot_vector(symbol, rotate_angle, filetypes[i].filetype);
} }
} else { } else {
error_number = dump_plot(symbol); error_number = txt_hex_plot(symbol);
} }
} else { } else {
return error_tag(ZINT_ERROR_INVALID_OPTION, symbol, 225, "Unknown output format"); 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); return error_tag(ZINT_ERROR_INVALID_DATA, symbol, -1, NULL);
} }
nRead += n; nRead += n;
} while (!feof(file) && (0 < n) && ((long) nRead < fileLen)); } while (!feof(file) && n > 0 && (long) nRead < fileLen);
if (file_opened) { if (file_opened) {
if (fclose(file) != 0) { if (fclose(file) != 0) {
+6 -6
View File
@@ -206,7 +206,7 @@ INTERNAL int zint_mailmark_4s(struct zint_symbol *symbol, unsigned char source[]
} }
memset(local_source + length, ' ', 22 - length); memset(local_source + length, ' ', 22 - length);
length = 22; length = 22;
} else if ((length > 22) && (length < 26)) { } else if (length > 22 && length < 26) {
memset(local_source + length, ' ', 26 - length); memset(local_source + length, ' ', 26 - length);
length = 26; 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 is in the range 0-4 */
format = z_ctoi(local_source[0]); 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)"); 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 is in the range 1-4 */
version_id = z_ctoi(local_source[1]) - 1; 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)"); 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 */ /* Class is in the range 0-9,A-E */
mail_class = z_ctoi(local_source[2]); 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, return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 584,
"Class (3rd character) out of range (0 to 9 and A to E)"); "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 */ /* Translate 4-state data pattern to symbol */
j = 0; j = 0;
for (i = 0, len = d - bar; i < len; i++) { 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, 0, j);
} }
z_set_module(symbol, 1, 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); z_set_module(symbol, 2, j);
} }
j += 2; j += 2;
+4 -4
View File
@@ -69,7 +69,7 @@ INTERNAL int zint_pharma(struct zint_symbol *symbol, unsigned char source[], int
} }
tester = z_to_int(source, length); 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); 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); 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)", return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 353, "Input value '%d' out of range (4 to 64570080)",
tester); tester);
} }
@@ -170,10 +170,10 @@ INTERNAL int zint_pharma_two(struct zint_symbol *symbol, unsigned char source[],
writer = 0; writer = 0;
for (loopey = 0; loopey < h; loopey++) { 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); 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); z_set_module(symbol, 1, writer);
} }
writer += 2; writer += 2;
+11 -11
View File
@@ -194,13 +194,13 @@ INTERNAL int zint_out_colour_char_to_rgb(const unsigned char ch, unsigned char *
unsigned char *blue) { unsigned char *blue) {
static const char chars[] = "WCBMRYGK"; static const char chars[] = "WCBMRYGK";
static const unsigned char colours[8][3] = { static const unsigned char colours[8][3] = {
{ 0xff, 0xff, 0xff, }, /* White */ { 0xFF, 0xFF, 0xFF, }, /* White */
{ 0, 0xff, 0xff, }, /* Cyan */ { 0, 0xFF, 0xFF, }, /* Cyan */
{ 0, 0, 0xff, }, /* Blue */ { 0, 0, 0xFF, }, /* Blue */
{ 0xff, 0, 0xff, }, /* Magenta */ { 0xFF, 0, 0xFF, }, /* Magenta */
{ 0xff, 0, 0, }, /* Red */ { 0xFF, 0, 0, }, /* Red */
{ 0xff, 0xff, 0, }, /* Yellow */ { 0xFF, 0xFF, 0, }, /* Yellow */
{ 0, 0xff, 0, }, /* Green */ { 0, 0xFF, 0, }, /* Green */
{ 0, 0, 0, }, /* Black */ { 0, 0, 0, }, /* Black */
}; };
int i = z_posn(chars, (const char) ch); 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; upceanflag = 8;
break; break;
} }
} else if ((symbol->symbology == BARCODE_UPCA) || (symbol->symbology == BARCODE_UPCA_CHK) } else if (symbol->symbology == BARCODE_UPCA || symbol->symbology == BARCODE_UPCA_CHK
|| (symbol->symbology == BARCODE_UPCA_CC)) { || symbol->symbology == BARCODE_UPCA_CC) {
main_width = 95 + comp_xoffset; /* UPC-A main symbol 95 modules wide */ main_width = 95 + comp_xoffset; /* UPC-A main symbol 95 modules wide */
upceanflag = 12; upceanflag = 12;
} else if ((symbol->symbology == BARCODE_UPCE) || (symbol->symbology == BARCODE_UPCE_CHK) } else if (symbol->symbology == BARCODE_UPCE || symbol->symbology == BARCODE_UPCE_CHK
|| (symbol->symbology == BARCODE_UPCE_CC)) { || symbol->symbology == BARCODE_UPCE_CC) {
main_width = 51 + comp_xoffset; /* UPC-E main symbol 51 modules wide */ main_width = 51 + comp_xoffset; /* UPC-E main symbol 51 modules wide */
upceanflag = 6; upceanflag = 6;
} }
+5 -5
View File
@@ -129,11 +129,11 @@ INTERNAL int zint_pcx_pixel_plot(struct zint_symbol *symbol, const unsigned char
previous = rle_row[0]; previous = rle_row[0];
run_count = 1; run_count = 1;
for (column = 1; column < bytes_per_line; column++) { /* Note going up to bytes_per_line */ 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++; run_count++;
} else { } else {
if (run_count > 1 || (previous & 0xc0) == 0xc0) { if (run_count > 1 || (previous & 0xC0) == 0xC0) {
run_count += 0xc0; run_count += 0xC0;
zint_fm_putc(run_count, fmp); zint_fm_putc(run_count, fmp);
} }
zint_fm_putc(previous, 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) { if (run_count > 1 || (previous & 0xC0) == 0xC0) {
run_count += 0xc0; run_count += 0xC0;
zint_fm_putc(run_count, fmp); zint_fm_putc(run_count, fmp);
} }
zint_fm_putc(previous, fmp); zint_fm_putc(previous, fmp);
+14 -14
View File
@@ -265,9 +265,9 @@ static int pdf_text_submode_length(const unsigned char chaine[], const int start
} else { } else {
/* Obliged to change table */ /* Obliged to change table */
int newtable; 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 */ /* 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 */ wnet += 2; /* AS+char */
continue; continue;
} }
@@ -341,16 +341,16 @@ static void pdf_appendix_d_encode(const unsigned char *chaine, short liste[3][PD
while (i < indexliste) { 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 */ /* Leave as numeric */
liste[0][last] = liste[0][i]; liste[0][last] = liste[0][i];
liste[1][last] = PDF_NUM; liste[1][last] = PDF_NUM;
liste[2][last] = liste[2][i]; liste[2][last] = liste[2][i];
stayintext = 0; stayintext = 0;
last++; last++;
} else if (((liste[1][i] == PDF_TEX) || (liste[1][i] == PDF_NUM)) } else if ((liste[1][i] == PDF_TEX || liste[1][i] == PDF_NUM)
&& (stayintext || i == indexliste - 1 || (liste[0][i] >= 5) && (stayintext || i == indexliste - 1 || liste[0][i] >= 5
|| (pdf_text_num_length(liste, indexliste, i) >= 5))) { || pdf_text_num_length(liste, indexliste, i) >= 5)) {
/* Set to text and combine additional text/short numeric segments */ /* Set to text and combine additional text/short numeric segments */
liste[0][last] = liste[0][i]; liste[0][last] = liste[0][i];
liste[1][last] = PDF_TEX; 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; next = i + 1;
while (next < indexliste) { 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; break;
} else if (liste[1][next] == PDF_BYT) { } else if (liste[1][next] == PDF_BYT) {
break; break;
@@ -383,12 +383,12 @@ static void pdf_appendix_d_encode(const unsigned char *chaine, short liste[3][PD
while (next < indexliste) { while (next < indexliste) {
if (liste[1][next] != PDF_BYT) { if (liste[1][next] != PDF_BYT) {
/* Check for case of a single byte shift from text mode */ /* 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; stayintext = 1;
break; 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; break;
} }
} }
@@ -465,9 +465,9 @@ static void pdf_textprocess(short *chainemc, int *p_mclength, const unsigned cha
} else { } else {
/* Obliged to change table */ /* Obliged to change table */
int newtable; 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 */ /* 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++] = 27; /* AS */
chainet[wnet++] = listet[1][j]; chainet[wnet++] = listet[1][j];
continue; continue;
@@ -1021,7 +1021,7 @@ static int pdf_initial(struct zint_symbol *symbol, const unsigned char chaine[],
do { do {
liste[1][indexliste] = mode; liste[1][indexliste] = mode;
liste[2][indexliste] = indexchaine; liste[2][indexliste] = indexchaine;
while ((liste[1][indexliste] == mode) && (indexchaine < length)) { while (liste[1][indexliste] == mode && indexchaine < length) {
liste[0][indexliste]++; liste[0][indexliste]++;
indexchaine++; indexchaine++;
mode = pdf_quelmode(chaine[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; 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); 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) { if (symbol->warn_level == WARN_FAIL_ALL) {
return ZINT_ERROR_INVALID_OPTION; 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"); error_number = z_errtxt_adj(ZINT_WARN_INVALID_OPTION, symbol, "%1$s%2$s", ", ignoring");
symbol->option_1 = -1; 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); 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) { if (symbol->warn_level == WARN_FAIL_ALL) {
return ZINT_ERROR_INVALID_OPTION; return ZINT_ERROR_INVALID_OPTION;
+1 -1
View File
@@ -346,7 +346,7 @@ INTERNAL int zint_msi_plessey(struct zint_symbol *symbol, unsigned char source[]
check_option -= 10; check_option -= 10;
no_checktext = 1; no_checktext = 1;
} }
if ((check_option < 0) || (check_option > 6)) { if (check_option < 0 || check_option > 6) {
check_option = 0; check_option = 0;
} }
+10 -10
View File
@@ -492,11 +492,11 @@ INTERNAL int zint_rm4scc(struct zint_symbol *symbol, unsigned char source[], int
writer = 0; writer = 0;
h = (int) strlen(height_pattern); h = (int) strlen(height_pattern);
for (loopey = 0; loopey < h; loopey++) { 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, 0, writer);
} }
z_set_module(symbol, 1, 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); z_set_module(symbol, 2, writer);
} }
writer += 2; writer += 2;
@@ -559,11 +559,11 @@ INTERNAL int zint_kix(struct zint_symbol *symbol, unsigned char source[], int le
writer = 0; writer = 0;
h = d - height_pattern; h = d - height_pattern;
for (loopey = 0; loopey < h; loopey++) { 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, 0, writer);
} }
z_set_module(symbol, 1, 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); z_set_module(symbol, 2, writer);
} }
writer += 2; writer += 2;
@@ -612,11 +612,11 @@ INTERNAL int zint_daft(struct zint_symbol *symbol, unsigned char source[], int l
writer = 0; writer = 0;
for (loopey = 0; loopey < length; loopey++) { 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, 0, writer);
} }
z_set_module(symbol, 1, 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); z_set_module(symbol, 2, writer);
} }
writer += 2; writer += 2;
@@ -705,7 +705,7 @@ INTERNAL int zint_japanpost(struct zint_symbol *symbol, unsigned char source[],
i = 0; i = 0;
inter_posn = 0; inter_posn = 0;
do { do {
if (z_isdigit(source[i]) || (source[i] == '-')) { if (z_isdigit(source[i]) || source[i] == '-') {
inter[inter_posn] = source[i]; inter[inter_posn] = source[i];
inter_posn++; inter_posn++;
} else { } else {
@@ -722,7 +722,7 @@ INTERNAL int zint_japanpost(struct zint_symbol *symbol, unsigned char source[],
inter_posn += 2; inter_posn += 2;
} }
i++; i++;
} while ((i < length) && (inter_posn < 20)); } while (i < length && inter_posn < 20);
if (i != length || inter[20] != '\0') { if (i != length || inter[20] != '\0') {
return z_errtxt(ZINT_ERROR_TOO_LONG, symbol, 477, 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; writer = 0;
h = d - pattern; h = d - pattern;
for (loopey = 0; loopey < h; loopey++) { 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, 0, writer);
} }
z_set_module(symbol, 1, 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); z_set_module(symbol, 2, writer);
} }
writer += 2; writer += 2;
+97 -146
View File
@@ -438,45 +438,44 @@ static int qr_binary(char binary[], int bp, const int version, const char mode[]
modebits = qr_mode_bits(version); modebits = qr_mode_bits(version);
do { do {
char data_block = mode[position]; const char block_mode = mode[position];
int short_data_block_length = 0; int block_length = 0;
int double_byte = 0; int double_byte = 0;
do { do {
if (data_block == 'B' && ddata[position + short_data_block_length] > 0xFF) { if (block_mode == 'B' && ddata[position + block_length] > 0xFF) {
double_byte++; double_byte++;
} }
short_data_block_length++; block_length++;
} while (((short_data_block_length + position) < length) } while (position + block_length < length && mode[position + block_length] == block_mode);
&& (mode[position + short_data_block_length] == data_block));
/* Mode indicator */ /* Mode indicator */
if (modebits) { 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': case 'K':
/* Kanji mode */ /* Kanji mode */
/* Character count indicator */ /* 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) { 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 */ /* Character representation */
for (i = 0; i < short_data_block_length; i++) { for (i = 0; i < block_length; i++) {
unsigned int jis = ddata[position + i]; unsigned int jis = ddata[position + i];
int prod; int prod;
if (jis >= 0x8140 && jis <= 0x9ffc) if (jis >= 0x8140 && jis <= 0x9FFC)
jis -= 0x8140; jis -= 0x8140;
else if (jis >= 0xe040 && jis <= 0xebbf) else if (jis >= 0xE040 && jis <= 0xEBBF)
jis -= 0xc140; jis -= 0xC140;
prod = ((jis >> 8) * 0xc0) + (jis & 0xff); prod = ((jis >> 8) * 0xC0) + (jis & 0xFF);
bp = z_bin_append_posn(prod, 13, binary, bp); 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 */ /* Byte mode */
/* Character count indicator */ /* Character count indicator */
bp = z_bin_append_posn(short_data_block_length + double_byte, qr_cci_bits(version, data_block), bp = z_bin_append_posn(block_length + double_byte, qr_cci_bits(version, block_mode), binary, bp);
binary, bp);
if (debug_print) { 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 */ /* Character representation */
for (i = 0; i < short_data_block_length; i++) { for (i = 0; i < block_length; i++) {
unsigned int byte = ddata[position + i]; unsigned int byte = ddata[position + i];
bp = z_bin_append_posn(byte, byte > 0xFF ? 16 : 8, binary, bp); 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; percent_count = 0;
if (gs1) { if (gs1) {
for (i = 0; i < short_data_block_length; i++) { for (i = 0; i < block_length; i++) {
if (ddata[position + i] == '%') { if (ddata[position + i] == '%') {
percent_count++; percent_count++;
} }
@@ -530,21 +528,20 @@ static int qr_binary(char binary[], int bp, const int version, const char mode[]
} }
/* Character count indicator */ /* Character count indicator */
bp = z_bin_append_posn(short_data_block_length + percent_count, qr_cci_bits(version, data_block), bp = z_bin_append_posn(block_length + percent_count, qr_cci_bits(version, block_mode), binary, bp);
binary, bp);
if (debug_print) { 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 */ /* Character representation */
i = 0; i = 0;
while (i < short_data_block_length) { while (i < block_length) {
int count; int count;
int first = 0, second = 0, prod; int first = 0, second = 0, prod;
if (percent == 0) { if (percent == 0) {
if (gs1 && (ddata[position + i] == '%')) { if (gs1 && ddata[position + i] == '%') {
first = QR_PERCENT; first = QR_PERCENT;
second = QR_PERCENT; second = QR_PERCENT;
count = 2; count = 2;
@@ -560,8 +557,8 @@ static int qr_binary(char binary[], int bp, const int version, const char mode[]
i++; i++;
prod = first; prod = first;
if (i < short_data_block_length && mode[position + i] == 'A') { if (i < block_length && mode[position + i] == 'A') {
if (gs1 && (ddata[position + i] == '%')) { if (gs1 && ddata[position + i] == '%') {
second = QR_PERCENT; second = QR_PERCENT;
count = 2; count = 2;
prod = (first * 45) + second; prod = (first * 45) + second;
@@ -585,8 +582,8 @@ static int qr_binary(char binary[], int bp, const int version, const char mode[]
prod = first; prod = first;
percent = 0; percent = 0;
if (i < short_data_block_length && mode[position + i] == 'A') { if (i < block_length && mode[position + i] == 'A') {
if (gs1 && (ddata[position + i] == '%')) { if (gs1 && ddata[position + i] == '%') {
second = QR_PERCENT; second = QR_PERCENT;
count = 2; count = 2;
prod = (first * 45) + second; prod = (first * 45) + second;
@@ -620,15 +617,15 @@ static int qr_binary(char binary[], int bp, const int version, const char mode[]
/* Numeric mode */ /* Numeric mode */
/* Character count indicator */ /* 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) { 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 */ /* Character representation */
i = 0; i = 0;
while (i < short_data_block_length) { while (i < block_length) {
int count; int count;
int first = 0, prod; int first = 0, prod;
@@ -636,12 +633,12 @@ static int qr_binary(char binary[], int bp, const int version, const char mode[]
count = 1; count = 1;
prod = first; 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]); int second = z_ctoi((const char) ddata[position + i + 1]);
count = 2; count = 2;
prod = (prod * 10) + second; 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]); int third = z_ctoi((const char) ddata[position + i + 2]);
count = 3; count = 3;
prod = (prod * 10) + third; prod = (prod * 10) + third;
@@ -664,7 +661,7 @@ static int qr_binary(char binary[], int bp, const int version, const char mode[]
break; break;
} }
position += short_data_block_length; position += block_length;
} while (position < length); } while (position < length);
return bp; return bp;
@@ -683,6 +680,8 @@ static int qr_binary_segs(unsigned char datastream[], const int version, const i
int toggle; int toggle;
char *binary = (char *) z_alloca(est_binlen + 12); char *binary = (char *) z_alloca(est_binlen + 12);
assert(seg_count > 0); /* Suppress clang-tidy clang-analyzer-core.uninitialized.Assign warning */
*binary = '\0'; *binary = '\0';
if (p_structapp) { if (p_structapp) {
@@ -753,7 +752,7 @@ static int qr_binary_segs(unsigned char datastream[], const int version, const i
toggle = 0; toggle = 0;
for (i = current_bytes; i < target_codewords; i++) { for (i = current_bytes; i < target_codewords; i++) {
if (toggle == 0) { if (toggle == 0) {
datastream[i] = 0xec; datastream[i] = 0xEC;
toggle = 1; toggle = 1;
} else { } else {
datastream[i] = 0x11; 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) { const int data_cw, const int blocks, const int debug_print) {
int ecc_cw; int ecc_cw;
int short_data_block_length; int short_data_block_length;
int qty_long_blocks;
int qty_short_blocks; int qty_short_blocks;
int ecc_block_length; int ecc_block_length;
int i, j, length_this_block, in_posn; 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); assert(blocks > 0);
short_data_block_length = data_cw / blocks; short_data_block_length = data_cw / blocks;
qty_long_blocks = data_cw % blocks; qty_short_blocks = blocks - data_cw % blocks;
qty_short_blocks = blocks - qty_long_blocks;
ecc_block_length = ecc_cw / blocks; ecc_block_length = ecc_cw / blocks;
/* Suppress some clang-tidy clang-analyzer-core.UndefinedBinaryOperatorResult/uninitialized.Assign warnings */ /* Suppress some clang-tidy clang-analyzer-core.UndefinedBinaryOperatorResult/uninitialized.Assign warnings */
assert(short_data_block_length > 0); assert(data_cw > 0);
assert(qty_long_blocks || qty_short_blocks); 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); data_block = (unsigned char *) z_alloca(short_data_block_length + 1);
ecc_block = (unsigned char *) z_alloca(ecc_block_length); 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; in_posn = 0;
for (i = 0; i < blocks; i++) { for (i = 0; i < blocks; i++) {
if (i < qty_short_blocks) { length_this_block = short_data_block_length + (i >= qty_short_blocks);
length_this_block = short_data_block_length;
} else {
length_this_block = short_data_block_length + 1;
}
for (j = 0; j < length_this_block; j++) { 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];
data_block[j] = datastream[in_posn + j]; /* NOLINT(clang-analyzer-core.uninitialized.Assign) */
} }
zint_rs_encode(&rs, length_this_block, data_block, ecc_block); 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++) { 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];
interleaved_data[(j * blocks) + i] = data_block[j]; /* NOLINT(clang-analyzer-core.uninitialized.Assign) */
} }
if (i >= qty_short_blocks) { 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 (xp = 0; xp < 7; xp++) {
for (yp = 0; yp < 7; yp++) { for (yp = 0; yp < 7; yp++) {
if (finder[yp] & 0x40 >> xp) { grid[((yp + y) * size) + (xp + x)] = 0x10 + !!(finder[yp] & (0x40 >> xp));
grid[((yp + y) * size) + (xp + x)] = 0x11;
} else {
grid[((yp + y) * size) + (xp + x)] = 0x10;
}
} }
} }
} }
@@ -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 (xp = 0; xp < 5; xp++) {
for (yp = 0; yp < 5; yp++) { for (yp = 0; yp < 5; yp++) {
if (alignment[yp] & 0x10 >> xp) { grid[((yp + y) * size) + (xp + x)] = 0x10 + !!(alignment[yp] & (0x10 >> xp));
grid[((yp + y) * size) + (xp + x)] = 0x11;
} else {
grid[((yp + y) * size) + (xp + x)] = 0x10;
}
} }
} }
} }
@@ -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 x = x_start - (row * 2);
int r = y * h_size; int r = y * h_size;
if ((x < 6) && (not_rmqr)) if (x < 6 && not_rmqr)
x--; /* skip over vertical timing pattern */ 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); grid[r + (x + 1)] = qr_cwbit(fullstream, i);
i++; i++;
} }
if (i < n) { if (i < n) {
if (!(grid[r + x] & 0xf0)) { if (!(grid[r + x] & 0xF0)) {
grid[r + x] = qr_cwbit(fullstream, i); grid[r + x] = qr_cwbit(fullstream, i);
i++; i++;
} }
@@ -1159,9 +1144,8 @@ static int qr_evaluate(unsigned char *local, const int size) {
for (x = 0; x < size - 1; x++) { for (x = 0; x < size - 1; x++) {
for (y = 0; y < size - 1; y++) { for (y = 0; y < size - 1; y++) {
k = local[(y * size) + x]; k = local[(y * size) + x];
if (((k == local[((y + 1) * size) + x]) && if (k == local[((y + 1) * size) + x] && k == local[(y * size) + (x + 1)]
(k == local[(y * size) + (x + 1)])) && && k == local[((y + 1) * size) + (x + 1)]) {
(k == local[((y + 1) * size) + (x + 1)])) {
result += 3; result += 3;
} }
} }
@@ -1178,12 +1162,12 @@ static int qr_evaluate(unsigned char *local, const int size) {
/* Vertical */ /* Vertical */
for (x = 0; x < size; x++) { for (x = 0; x < size; x++) {
for (y = 0; y <= (size - 7); y++) { for (y = 0; y <= (size - 7); y++) {
if (local[y * size + x] && !local[(y + 1) * size + x] && local[(y + 2) * 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 + 3) * size + x] && local[(y + 4) * size + x]
!local[(y + 5) * size + x] && local[(y + 6) * size + x]) { && !local[(y + 5) * size + x] && local[(y + 6) * size + x]) {
/* Pattern found, check before and after */ /* Pattern found, check before and after */
beforeCount = 0; 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 */ if (b < 0) { /* Count < edge as whitespace */
beforeCount = 4; beforeCount = 4;
break; break;
@@ -1198,7 +1182,7 @@ static int qr_evaluate(unsigned char *local, const int size) {
result += 40; result += 40;
} else { } else {
afterCount = 0; 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 */ if (a >= size) { /* Count > edge as whitespace */
afterCount = 4; afterCount = 4;
break; break;
@@ -1225,7 +1209,7 @@ static int qr_evaluate(unsigned char *local, const int size) {
if (memcmp(local + r + x, h1011101, 7) == 0) { if (memcmp(local + r + x, h1011101, 7) == 0) {
/* Pattern found, check before and after */ /* Pattern found, check before and after */
beforeCount = 0; 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 */ if (b < 0) { /* Count < edge as whitespace */
beforeCount = 4; beforeCount = 4;
break; break;
@@ -1241,7 +1225,7 @@ static int qr_evaluate(unsigned char *local, const int size) {
result += 40; result += 40;
} else { } else {
afterCount = 0; 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 */ if (a >= size) { /* Count > edge as whitespace */
afterCount = 4; afterCount = 4;
break; 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++) { 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. */ /* 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) { if (((y + x) & 1) == 0) {
mask[r + x] |= 0x01; 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; mask[r + x] |= 0x02;
} }
} }
if ((x % 3) == 0) { if (x % 3 == 0) {
mask[r + x] |= 0x04; mask[r + x] |= 0x04;
} }
if (!fast_encode) { if (!fast_encode) {
if (((y + x) % 3) == 0) { if ((y + x) % 3 == 0) {
mask[r + x] |= 0x08; mask[r + x] |= 0x08;
} }
} }
if ((((y / 2) + (x / 3)) & 1) == 0) { if (((y / 2 + x / 3) & 1) == 0) {
mask[r + x] |= 0x10; mask[r + x] |= 0x10;
} }
if (!fast_encode) { if (!fast_encode) {
if ((y * x) % 6 == 0) { /* Equivalent to (y * x) % 2 + (y * x) % 3 == 0 */ if ((y * x) % 6 == 0) { /* Equivalent to (y * x) % 2 + (y * x) % 3 == 0 */
mask[r + x] |= 0x20; 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; 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; 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) { if (mask[k] & bit) {
local[k] = grid[k] ^ 0x01; local[k] = grid[k] ^ 0x01;
} else { } else {
local[k] = grid[k] & 0x0f; local[k] = grid[k] & 0x0F;
} }
} }
qr_add_format_info(local, size, ecc_level, pattern); 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 { do {
count++; count++;
} while (((i + count) < length) && (mode[i + count] == start_mode)); } while (i + count < length && mode[i + count] == start_mode);
return count; return count;
} }
@@ -1505,7 +1489,7 @@ static int qr_calc_binlen(const int version, char mode[], const unsigned int dda
break; break;
case 'B': case 'B':
for (j = i; j < (i + blocklength); j++) { for (j = i; j < (i + blocklength); j++) {
if (ddata[j] > 0xff) { if (ddata[j] > 0xFF) {
count += 16; count += 16;
} else { } else {
count += 8; 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, est_binlen = qr_calc_binlen_segs(40, mode, ddata, local_segs, seg_count, p_structapp, 0 /*mode_preset*/, gs1,
debug_print); 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; ecc_level = symbol->option_1 - 1;
} else { } else {
ecc_level = QR_LEVEL_L; ecc_level = QR_LEVEL_L;
} }
max_cw = qr_data_codewords[ecc_level][39]; 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) { if (ecc_level == QR_LEVEL_L) {
return ZEXT z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 567, return ZEXT z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 567,
"Input too long, requires %1$d codewords (maximum %2$d)", (est_binlen + 7) / 8, "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; autosize = 40;
for (i = 39; i >= 0; i--) { 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; 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, est_binlen = qr_calc_binlen_segs(autosize - 1, mode, ddata, local_segs, seg_count, p_structapp,
0 /*mode_preset*/, gs1, debug_print); 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; canShrink = 0;
} }
@@ -1794,7 +1778,7 @@ INTERNAL int zint_qrcode(struct zint_symbol *symbol, struct zint_seg segs[], con
version = autosize; 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, /* 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 then use the size the user has selected, and re-optimise for this
symbol size. symbol size.
@@ -1981,15 +1965,9 @@ static void microqr_setup_grid(unsigned char *grid, const int size) {
/* Add timing patterns */ /* Add timing patterns */
for (i = 0; i < size; i++) { for (i = 0; i < size; i++) {
if (toggle == 1) { grid[i] = 0x20 + toggle;
grid[i] = 0x21; grid[i * size] = 0x20 + toggle;
grid[(i * size)] = 0x21; toggle = !toggle;
toggle = 0;
} else {
grid[i] = 0x20;
grid[(i * size)] = 0x20;
toggle = 1;
}
} }
/* Add finder patterns */ /* Add finder patterns */
@@ -2022,22 +2000,14 @@ static void microqr_populate_grid(unsigned char *grid, const int size, const cha
do { do {
int x = (size - 2) - (row * 2); int x = (size - 2) - (row * 2);
if (!(grid[(y * size) + (x + 1)] & 0xf0)) { if (!(grid[(y * size) + (x + 1)] & 0xF0)) {
if (full_stream[i] == '1') { grid[(y * size) + (x + 1)] = full_stream[i] == '1';
grid[(y * size) + (x + 1)] = 0x01;
} else {
grid[(y * size) + (x + 1)] = 0x00;
}
i++; i++;
} }
if (i < bp) { if (i < bp) {
if (!(grid[(y * size) + x] & 0xf0)) { if (!(grid[(y * size) + x] & 0xF0)) {
if (full_stream[i] == '1') { grid[(y * size) + x] = full_stream[i] == '1';
grid[(y * size) + x] = 0x01;
} else {
grid[(y * size) + x] = 0x00;
}
i++; i++;
} }
} }
@@ -2108,20 +2078,20 @@ static int microqr_apply_bitmask(unsigned char *grid, const int size, const int
r = y * size; r = y * size;
for (x = 0; x < size; x++) { for (x = 0; x < size; x++) {
if (!(grid[r + x] & 0xf0)) { if (!(grid[r + x] & 0xF0)) {
if ((y & 1) == 0) { if ((y & 1) == 0) {
mask[r + x] |= 0x01; mask[r + x] |= 0x01;
} }
if ((((y / 2) + (x / 3)) & 1) == 0) { if (((y / 2 + x / 3) & 1) == 0) {
mask[r + x] |= 0x02; 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; 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; mask[r + x] |= 0x08;
} }
} }
@@ -2133,7 +2103,7 @@ static int microqr_apply_bitmask(unsigned char *grid, const int size, const int
} else { } else {
for (k = 0; k < size_squared; k++) { for (k = 0; k < size_squared; k++) {
if (grid[k] & 0x01) { if (grid[k] & 0x01) {
eval[k] = mask[k] ^ 0xff; eval[k] = mask[k] ^ 0xFF;
} else { } else {
eval[k] = mask[k]; eval[k] = mask[k];
} }
@@ -2312,7 +2282,7 @@ INTERNAL int zint_microqr(struct zint_symbol *symbol, unsigned char source[], in
} }
/* Get version from user */ /* 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))) { if (symbol->option_2 == 1 && (i = z_not_sane(NEON_F, source, length))) {
return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 758, return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 758,
"Invalid character at position %d in input for Version M1 (digits only)", i); "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 */ /* Add timing patterns - top and bottom */
for (i = 0; i < h_size; i++) { for (i = 0; i < h_size; i++) {
if (i % 2) { grid[i] = 0x20 + !(i & 1);
grid[i] = 0x20; grid[((v_size - 1) * h_size) + i] = 0x20 + !(i & 1);
grid[((v_size - 1) * h_size) + i] = 0x20;
} else {
grid[i] = 0x21;
grid[((v_size - 1) * h_size) + i] = 0x21;
}
} }
/* Add timing patterns - left and right */ /* Add timing patterns - left and right */
for (i = 0; i < v_size; i++) { for (i = 0; i < v_size; i++) {
if (i % 2) { grid[i * h_size] = 0x20 + !(i & 1);
grid[i * h_size] = 0x20; grid[(i * h_size) + (h_size - 1)] = 0x20 + !(i & 1);
grid[(i * h_size) + (h_size - 1)] = 0x20;
} else {
grid[i * h_size] = 0x21;
grid[(i * h_size) + (h_size - 1)] = 0x21;
}
} }
/* Add finder pattern */ /* 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 */ /* Add finder sub-pattern to bottom right */
for (i = 0; i < 5; i++) { for (i = 0; i < 5; i++) {
for (j = 0; j < 5; j++) { for (j = 0; j < 5; j++) {
if (alignment[j] & 0x10 >> i) { grid[((i + v_size - 5) * h_size) + (h_size - 5) + j] = 0x10 + !!(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;
}
} }
} }
@@ -2600,11 +2556,7 @@ static void rmqr_setup_grid(unsigned char *grid, const int h_size, const int v_s
if (finder_position != 0) { if (finder_position != 0) {
for (j = 0; j < v_size; j++) { for (j = 0; j < v_size; j++) {
if (j % 2) { grid[(j * h_size) + finder_position] = 0x10 + !(j & 1);
grid[(j * h_size) + finder_position] = 0x10;
} else {
grid[(j * h_size) + finder_position] = 0x11;
}
} }
/* Top square */ /* 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"); 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)", return z_errtxtf(ZINT_ERROR_INVALID_OPTION, symbol, 579, "Version '%d' out of range (1 to 38)",
symbol->option_2); 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; ecc_level = symbol->option_1 == 4 ? QR_LEVEL_H : QR_LEVEL_M;
max_cw = rmqr_data_codewords[ecc_level >> 1][31]; 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, 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)", "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); 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); 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 */ /* User specified symbol size */
version = symbol->option_2 - 1; version = symbol->option_2 - 1;
est_binlen = qr_calc_binlen_segs(RMQR_VERSION + version, mode, ddata, local_segs, seg_count, 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]; target_codewords = rmqr_data_codewords[ecc_level >> 1][version];
blocks = rmqr_blocks[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 */ /* User has selected a symbol too small for the data */
assert(symbol->option_2 > 0); assert(symbol->option_2 > 0);
return ZEXT z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 560, 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++) { for (i = 0; i < v_size; i++) {
int r = i * h_size; int r = i * h_size;
for (j = 0; j < h_size; j++) { for (j = 0; j < h_size; j++) {
if ((grid[r + j] & 0xf0) == 0) { if ((grid[r + j] & 0xF0) == 0) {
/* This is a data module */ /* 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 */ /* This module needs to be changed */
grid[r + j] ^= 0x01; 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 (i = 0; i < 5; i++) {
for (j = 0; j < 3; j++) { for (j = 0; j < 3; j++) {
grid[(h_size * (i + 1)) + j + 8] = (left_format_info >> ((j * 5) + i)) & 0x01; 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)] grid[(h_size * (i + v_size - 6)) + j + (h_size - 8)] = (right_format_info >> ((j * 5) + i)) & 0x01;
= (right_format_info >> ((j * 5) + i)) & 0x01;
} }
} }
grid[(h_size * 1) + 11] = (left_format_info >> 15) & 0x01; grid[(h_size * 1) + 11] = (left_format_info >> 15) & 0x01;
+7 -7
View File
@@ -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}, {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} /*bg*/, {0} /*fg*/, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, /* 0-9 */
{0}, {0}, {0}, {0}, {0}, {0}, {0}, /* :;<=>?@ */ {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, 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}, { 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 */ {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 */ { 0xFF, 0xFF, 0xFF } /*White*/, {0}, { 0xFF, 0xFF, 0 } /*Yellow*/, {0} /* W-Z */
}; };
int row; int row;
int plot_alpha = 0; int plot_alpha = 0;
@@ -340,7 +340,7 @@ static void draw_letter(unsigned char *pixelbuf, const unsigned char letter, int
return; return;
} }
if ((letter >= 127) && (letter < 161)) { if (letter >= 127 && letter < 161) {
return; 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++) { for (y = -radius_i; y <= radius_i; y++) {
const int y_squared = y * y; const int y_squared = y * y;
for (x = -radius_i; x <= radius_i; x++) { 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); 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); const int fill = z_module_is_set(symbol, r, i);
for (block_width = 1; (i + block_width < symbol->width) for (block_width = 1; (i + block_width < symbol->width)
&& z_module_is_set(symbol, r, i + block_width) == fill; block_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; int addon_row_height_si;
const int addon_row_adj_si = (int) ceilf((font_height + symbol->text_gap) * 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, copy_bar_line(pixelbuf, xoffset_si, main_width * si, yposn_si, row_height_si, image_width,
+4 -4
View File
@@ -72,7 +72,7 @@
/* `combins()' in ISO/IEC 24724:2011 Annex B */ /* `combins()' in ISO/IEC 24724:2011 Annex B */
/**************************************************************************** /****************************************************************************
* dbar_combins(n,r): returns the number of Combinations of r selected from n: * 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) { static int dbar_combins(const int n, const int r) {
int i; int i;
@@ -126,7 +126,7 @@ static void dbar_getWidths(int widths[], int val, int n, const int elements, con
/* Get all combinations */ /* Get all combinations */
subVal = dbar_combins(n - elmWidth - 1, elements - bar - 2); subVal = dbar_combins(n - elmWidth - 1, elements - bar - 2);
/* Less combinations with no single-module element */ /* 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); subVal -= dbar_combins(n - elmWidth - (elements - bar), elements - bar - 2);
} }
/* Less combinations with elements > maxVal */ /* 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 */ cols_per_row = 2; /* Default */
if (symbol->option_2 >= 1 && symbol->option_2 <= 11) { if (symbol->option_2 >= 1 && symbol->option_2 <= 11) {
cols_per_row = symbol->option_2; 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 /* "There shall be a minimum of four symbol characters in the
first row of an RSS Expanded Stacked symbol when it is the linear first row of an RSS Expanded Stacked symbol when it is the linear
component of an EAN.UCC Composite symbol." */ 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++; reader++;
current_block++; current_block++;
} while ((reader < cols_per_row) && (current_block < codeblocks)); } while (reader < cols_per_row && current_block < codeblocks);
/* Row Stop */ /* Row Stop */
sub_elements[elements_in_sub++] = 1; /* Right guard */ sub_elements[elements_in_sub++] = 1; /* Right guard */
+4 -4
View File
@@ -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) */ /* 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) { 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); svg_put_fattrib(" opacity=\"", 3, val, fmp);
} }
if (close) { if (close) {
@@ -139,12 +139,12 @@ INTERNAL int zint_svg_plot(struct zint_symbol *symbol) {
char *html_string; char *html_string;
(void) zint_out_colour_get_rgb(symbol->fgcolour, &fgred, &fggreen, &fgblue, &fg_alpha); (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; fg_alpha_opacity = fg_alpha / 255.0f;
} }
sprintf(fgcolour_string, "%02X%02X%02X", fgred, fggreen, fgblue); sprintf(fgcolour_string, "%02X%02X%02X", fgred, fggreen, fgblue);
(void) zint_out_colour_get_rgb(symbol->bgcolour, &bgred, &bggreen, &bgblue, &bg_alpha); (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; bg_alpha_opacity = bg_alpha / 255.0f;
} }
sprintf(bgcolour_string, "%02X%02X%02X", bgred, bggreen, bgblue); 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_radius = 0.25f * previous_diameter;
half_sqrt3_radius = 0.43301270189221932338f * 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("M", 2, hex->x, fmp);
zint_fm_putsf(" ", 2, hex->y + radius, fmp); zint_fm_putsf(" ", 2, hex->y + radius, fmp);
zint_fm_putsf("L", 2, hex->x + half_sqrt3_radius, fmp); zint_fm_putsf("L", 2, hex->x + half_sqrt3_radius, fmp);
+10 -5
View File
@@ -39,7 +39,7 @@
#include "../common.h" #include "../common.h"
#include "../filemem.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; int debug = p_ctx->debug;
struct item { struct item {
@@ -68,6 +68,9 @@ static void test_svg(const testCtx *const p_ctx) {
" </g>\n" " </g>\n"
"</svg>\n" "</svg>\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 data_size = ARRAY_SIZE(data);
int i, length, ret; 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_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", assert_equal(symbol->memfile_size, expected_size, "i:%d memfile_size %d != %d (\"%.*s\", \"%s\") (%s)\n",
i, symbol->memfile_size, expected_size, symbol->errtxt); 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); 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 { } else {
assert_null(symbol->memfile, "i:%d memfile != NULL (%s)\n", i, symbol->errtxt); 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); 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[]) { int main(int argc, char *argv[]) {
testFunction funcs[] = { /* name, func */ testFunction funcs[] = { /* name, func */
{ "test_svg", test_svg }, { "test_file", test_file },
{ "test_putsf", test_putsf }, { "test_putsf", test_putsf },
{ "test_printf", test_printf }, { "test_printf", test_printf },
{ "test_seek", test_seek }, { "test_seek", test_seek },
+3 -2
View File
@@ -1577,7 +1577,7 @@ static void test_encode_print_outfile_directory(const testCtx *const p_ctx) {
int ret; int ret;
struct zint_symbol *symbol = NULL; struct zint_symbol *symbol = NULL;
char dirname[] = "outdir.txt"; 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; (void)p_ctx;
@@ -1593,7 +1593,8 @@ static void test_encode_print_outfile_directory(const testCtx *const p_ctx) {
strcpy(symbol->outfile, dirname); strcpy(symbol->outfile, dirname);
ret = ZBarcode_Encode_and_Print(symbol, TCU("1"), 0, 0); 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_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); ret = testUtilRmDir(dirname);
assert_zero(ret, "testUtilRmDir(%s) %d != 0 (%d: %s)\n", dirname, ret, errno, strerror(errno)); assert_zero(ret, "testUtilRmDir(%s) %d != 0 (%d: %s)\n", dirname, ret, errno, strerror(errno));
+34 -34
View File
@@ -196,19 +196,19 @@ static void ult_gf283(const short DataSize, const short EccSize, int Message[])
ult_genPoly(EccSize, gPoly, gfPwr, gfLog); ult_genPoly(EccSize, gPoly, gfPwr, gfLog);
/* zero all EccSize codeword values */ /* 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 */ /* 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 */ /* add zeroes to pad left end Message[] for truncated codewords */
j++; j++;
for (i = 0; i < j; i++) Message[i] = 0; for (i = 0; i < j; i++) Message[i] = 0;
/* generate (EccSize) Reed-Solomon checkwords */ /* 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; 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 Message[j + DataSize + i] = (Message[j + DataSize + i + 1] + 283
- ULT_GFMUL(t, gPoly[EccSize - 1 - i])) % 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++) { for (j = 0; j < 27; j++) {
latch = 0; latch = 0;
fraglen = (int) strlen(ult_fragment[j]); fraglen = (int) strlen(ult_fragment[j]);
if ((position + fraglen) <= length) { if (position + fraglen <= length) {
latch = 1; latch = 1;
for (k = 0; k < fraglen; k++) { for (k = 0; k < fraglen; k++) {
if (source[position + k] != ult_fragment[j][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; i = in_locn;
while ((i < length) && (i < end_char)) { while (i < length && i < end_char) {
if (gs1 && source[i] == '\x1D') { if (gs1 && source[i] == '\x1D') {
cw[codeword_count] = 268; /* FNC1 */ cw[codeword_count] = 268; /* FNC1 */
} else { } else {
@@ -284,7 +284,7 @@ static float ult_look_ahead_ascii(unsigned char source[], const int length, cons
const int gs1) { const int gs1) {
int codeword_count = 0; int codeword_count = 0;
int i; int i;
int first_digit, second_digit, done; int done;
int letters_encoded = 0; int letters_encoded = 0;
if (current_mode == ULT_EIGHTBIT_MODE) { 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 */ /* Check for double digits */
done = 0; done = 0;
if (i + 1 < length) { if (i + 1 < length) {
first_digit = z_posn(ult_digit, source[i]); const int first_digit = z_posn(ult_digit, source[i]);
second_digit = z_posn(ult_digit, source[i + 1]); const int second_digit = z_posn(ult_digit, source[i + 1]);
if ((first_digit != -1) && (second_digit != -1)) { if (first_digit != -1 && second_digit != -1) {
/* Double digit can be encoded */ /* 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 */ /* Double digit numerics */
cw[codeword_count] = (10 * first_digit) + second_digit + 128; cw[codeword_count] = (10 * first_digit) + second_digit + 128;
codeword_count++; codeword_count++;
i += 2; i += 2;
done = 1; 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 */ /* Single digit followed by selected decimal point character */
cw[codeword_count] = first_digit + 228; cw[codeword_count] = first_digit + 228;
codeword_count++; codeword_count++;
i += 2; i += 2;
done = 1; 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 */ /* Selected decimal point character followed by single digit */
cw[codeword_count] = second_digit + 238; cw[codeword_count] = second_digit + 238;
codeword_count++; codeword_count++;
i += 2; i += 2;
done = 1; 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 */ /* Single digit or decimal point followed by field deliminator */
cw[codeword_count] = first_digit + 248; cw[codeword_count] = first_digit + 248;
codeword_count++; codeword_count++;
i += 2; i += 2;
done = 1; 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 */ /* Field deliminator followed by single digit or decimal point */
cw[codeword_count] = second_digit + 259; cw[codeword_count] = second_digit + 259;
codeword_count++; codeword_count++;
@@ -353,7 +353,7 @@ static float ult_look_ahead_ascii(unsigned char source[], const int length, cons
codeword_count++; codeword_count++;
i++; i++;
} }
} while ((i < length) && (i < end_char) && (source[i] < 0x80)); } while (i < length && i < end_char && source[i] < 0x80);
letters_encoded = i - in_locn; letters_encoded = i - in_locn;
if (encoded != NULL) { if (encoded != NULL) {
@@ -413,7 +413,7 @@ static int ult_get_subset(const unsigned char source[], const int length, const
int subset = 0; int subset = 0;
fragno = ult_find_fragment(source, length, in_locn); fragno = ult_find_fragment(source, length, in_locn);
if ((fragno != -1) && (fragno != 26)) { if (fragno != -1 && fragno != 26) {
subset = 3; subset = 3;
} else if (current_subset == 2) { } else if (current_subset == 2) {
if (z_posn(ult_c43_set2, source[in_locn]) != -1) { 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 */ /* Check for permissable URL C43 macro sequences, otherwise encode directly */
fragno = ult_find_fragment(source, length, sublocn); fragno = ult_find_fragment(source, length, sublocn);
if ((fragno == 2) || (fragno == 3)) { if (fragno == 2 || fragno == 3) {
/* http://www. > http:// */ /* http://www. > http:// */
/* https://www. > https:// */ /* https://www. > https:// */
fragno -= 2; fragno -= 2;
@@ -499,7 +499,7 @@ static float ult_look_ahead_c43(const unsigned char source[], const int length,
if (subset == 1) { if (subset == 1) {
cw[codeword_count] = 260; /* C43 Compaction Submode C1 */ cw[codeword_count] = 260; /* C43 Compaction Submode C1 */
codeword_count++; codeword_count++;
} else if ((subset == 2) || (subset == 3)) { } else if (subset == 2 || subset == 3) {
cw[codeword_count] = 266; /* C43 Compaction Submode C2 */ cw[codeword_count] = 266; /* C43 Compaction Submode C2 */
codeword_count++; codeword_count++;
} }
@@ -510,14 +510,14 @@ static float ult_look_ahead_c43(const unsigned char source[], const int length,
if (subset == 1) { if (subset == 1) {
cw[codeword_count] = 278; /* C43 Compaction Submode C1 */ cw[codeword_count] = 278; /* C43 Compaction Submode C1 */
codeword_count++; codeword_count++;
} else if ((subset == 2) || (subset == 3)) { } else if (subset == 2 || subset == 3) {
cw[codeword_count] = 280; /* C43 Compaction Submode C2 */ cw[codeword_count] = 280; /* C43 Compaction Submode C2 */
codeword_count++; codeword_count++;
} }
} }
unshift_set = subset; unshift_set = subset;
while ((sublocn < length) && (sublocn < end_char)) { while (sublocn < length && sublocn < end_char) {
/* Check for FNC1 */ /* Check for FNC1 */
if (gs1 && source[sublocn] == '\x1D') { if (gs1 && source[sublocn] == '\x1D') {
break; break;
@@ -529,7 +529,7 @@ static float ult_look_ahead_c43(const unsigned char source[], const int length,
break; 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)) { if (ult_c43_should_latch_other(source, length, sublocn, subset)) {
subcw[subcodeword_count] = 42; /* Latch to other C43 set */ subcw[subcodeword_count] = 42; /* Latch to other C43 set */
subcodeword_count++; subcodeword_count++;
@@ -681,10 +681,10 @@ static int ult_generate_codewords(struct zint_symbol *symbol, const unsigned cha
mode[input_locn] = 'a'; mode[input_locn] = 'a';
current_mode = ULT_ASCII_MODE; 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'; mode[input_locn] = 'c';
current_mode = ULT_C43_MODE; 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'; mode[input_locn] = '8';
current_mode = ULT_EIGHTBIT_MODE; 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; codewords[0] = 272;
} }
} else { } 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 */ /* ECI indicates use of character set within ISO/IEC 8859 */
codewords[0] = 257 + (eci - 3); codewords[0] = 257 + (eci - 3);
if (codewords[0] > 267) { if (codewords[0] > 267) {
/* Avoids ECI 14 for non-existant ISO/IEC 8859-12 */ /* Avoids ECI 14 for non-existant ISO/IEC 8859-12 */
codewords[0]--; codewords[0]--;
} }
} else if ((eci > 18) && (eci <= 898)) { } else if (eci > 18 && eci <= 898) {
/* ECI indicates use of character set outside ISO/IEC 8859 */ /* ECI indicates use of character set outside ISO/IEC 8859 */
codewords[0] = 275 + (eci / 256); codewords[0] = 275 + (eci / 256);
codewords[1] = 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) { } else if (eci == 899) {
/* Non-language byte data */ /* Non-language byte data */
codewords[0] = 280; 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) */ /* ECI beyond 899 needs to use fixed length encodable ECI invocation (section 7.6.2) */
/* Encode as 3 codewords */ /* Encode as 3 codewords */
codewords[0] = 257; /* ISO/IEC 8859-1 used to enter 8-bit mode */ 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); int fragno = ult_find_fragment(source, length, 0);
/* Check for http:// at start of input */ /* Check for http:// at start of input */
if ((fragno == 0) || (fragno == 2)) { if (fragno == 0 || fragno == 2) {
codewords[0] = 281; codewords[0] = 281;
source += 7; source += 7;
length -= 7; length -= 7;
symbol_mode = ULT_EIGHTBIT_MODE; symbol_mode = ULT_EIGHTBIT_MODE;
/* Check for https:// at start of input */ /* Check for https:// at start of input */
} else if ((fragno == 1) || (fragno == 3)) { } else if (fragno == 1 || fragno == 3) {
codewords[0] = 282; codewords[0] = 282;
source += 8; source += 8;
length -= 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 */ /* 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; ecc_level = 2;
} else { } else {
ecc_level = symbol->option_1 - 1; 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) { if (ecc_level == 0) {
qcc = 3; qcc = 3;
} else { } else {
if ((data_cw_count % 25) == 0) { if (data_cw_count % 25 == 0) {
qcc = ult_kec[ecc_level] * (data_cw_count / 25) + 3 + 2; qcc = ult_kec[ecc_level] * (data_cw_count / 25) + 3 + 2;
} else { } else {
qcc = ult_kec[ecc_level] * ((data_cw_count / 25) + 1) + 3 + 2; 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; pads = 0;
columns = total_cws / rows; columns = total_cws / rows;
} else { } else {
@@ -1199,7 +1199,7 @@ INTERNAL int zint_ultra(struct zint_symbol *symbol, struct zint_seg segs[], cons
for (j = 0; j < 5; j++) { for (j = 0; j < 5; j++) {
tilepat[4 - j] = ult_colour[(ult_tiles[codeword[i]] >> (3 * j)) & 0x07]; tilepat[4 - j] = ult_colour[(ult_tiles[codeword[i]] >> (3 * j)) & 0x07];
} }
if ((tiley + 1) >= total_height) { if (tiley + 1 >= total_height) {
tiley = 0; tiley = 0;
tilex++; tilex++;
+3 -4
View File
@@ -222,7 +222,7 @@ static int upce_cc(struct zint_symbol *symbol, unsigned char source[], int lengt
equivalent[3] = source[2]; equivalent[3] = source[2];
equivalent[9] = source[3]; equivalent[9] = source[3];
equivalent[10] = source[4]; 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" */ /* Note 1 - "X3 shall not be equal to 0, 1 or 2" */
return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 271, return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 271,
"For this UPC-E zero suppression, 3rd character cannot be \"0\", \"1\" or \"2\" (%.*s)", "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; 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); memcpy(d, EANsetB[gtin[i] - '0'], 4);
} else { } else {
memcpy(d, EANsetA[gtin[i] - '0'], 4); 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 (length == 13) /* Using 13 character ISBN */ {
if (!(((source[0] == '9') && (source[1] == '7')) && if (source[0] != '9' || source[1] != '7' || (source[2] != '8' && source[2] != '9')) {
((source[2] == '8') || (source[2] == '9')))) {
return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 279, return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 279,
"Invalid ISBN (must begin with \"978\" or \"979\")"); "Invalid ISBN (must begin with \"978\" or \"979\")");
} }
+6 -6
View File
@@ -218,7 +218,7 @@ static void vector_scale(struct zint_symbol *symbol, const int file_type) {
scale = 0.2f; 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 */ /* Increase size to overcome limitations in EMF file format */
scale *= 20; scale *= 20;
} }
@@ -355,7 +355,7 @@ static void vector_rotate(struct zint_symbol *symbol, const int rotate_angle) {
string = string->next; string = string->next;
} }
if ((rotate_angle == 90) || (rotate_angle == 270)) { if (rotate_angle == 90 || rotate_angle == 270) {
temp = symbol->vector->height; temp = symbol->vector->height;
symbol->vector->height = symbol->vector->width; symbol->vector->height = symbol->vector->width;
symbol->vector->width = temp; symbol->vector->width = temp;
@@ -372,8 +372,8 @@ static void vector_reduce_rectangles(struct zint_symbol *symbol) {
target = prev->next; target = prev->next;
while (target) { while (target) {
if ((rect->x == target->x) && (rect->width == target->width) if (rect->x == target->x && rect->width == target->width && z_stripf(rect->y + rect->height) == target->y
&& (z_stripf(rect->y + rect->height) == target->y) && (rect->colour == target->colour)) { && rect->colour == target->colour) {
rect->height += target->height; rect->height += target->height;
prev->next = target->next; prev->next = target->next;
free(target); free(target);
@@ -492,7 +492,7 @@ INTERNAL int zint_plot_vector(struct zint_symbol *symbol, int rotate_angle, int
xoffset_comp = xoffset + comp_xoffset; 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) { if (symbol->dot_size < 1.0f) {
dot_overspill = 0.0f; dot_overspill = 0.0f;
/* Offset (1 - dot_size) / 2 + dot_radius == (1 - dot_size + dot_size) / 2 == 1 / 2 */ /* 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) for (block_width = 1; (i + block_width < symbol->width)
&& z_module_is_set(symbol, r, i + block_width) == fill; block_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; addon_text_yposn = yposn + font_height - digit_ascender;
if (addon_text_yposn < 0.0f) { if (addon_text_yposn < 0.0f) {
addon_text_yposn = 0.0f; addon_text_yposn = 0.0f;
+3 -3
View File
@@ -333,7 +333,7 @@
<h1 class="title">Zint Barcode Generator and Zint Barcode Studio User <h1 class="title">Zint Barcode Generator and Zint Barcode Studio User
Manual</h1> Manual</h1>
<p class="author">Version 2.15.0.9</p> <p class="author">Version 2.15.0.9</p>
<p class="date">April 2025</p> <p class="date">August 2025</p>
</header> </header>
<nav id="TOC" role="doc-toc"> <nav id="TOC" role="doc-toc">
<ul> <ul>
@@ -3112,8 +3112,8 @@ the ECI codes.</p>
<p>Zint can output a representation of the symbol data as a set of <p>Zint can output a representation of the symbol data as a set of
hexadecimal values if asked to output to a text file hexadecimal values if asked to output to a text file
(<code>"*.txt"</code>) or if given the option (<code>"*.txt"</code>) or if given the option
<code>--filetype=txt</code>. This can be used for test and diagnostic <code>--filetype=txt</code> or the option <code>--dump</code>. This can
purposes.</p> be used for test and diagnostic purposes.</p>
<p>Additional options are available which are specific to certain <p>Additional options are available which are specific to certain
symbologies. These may, for example, control the amount of error symbologies. These may, for example, control the amount of error
correction data or the size of the symbol. These options are discussed correction data or the size of the symbol. These options are discussed
+3 -2
View File
@@ -1,6 +1,6 @@
% Zint Barcode Generator and Zint Barcode Studio User Manual % Zint Barcode Generator and Zint Barcode Studio User Manual
% Version 2.15.0.9 % Version 2.15.0.9
% April 2025 % August 2025
# 1. Introduction # 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 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 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. Additional options are available which are specific to certain symbologies.
These may, for example, control the amount of error correction data or the size These may, for example, control the amount of error correction data or the size
+3 -2
View File
@@ -1,6 +1,6 @@
Zint Barcode Generator and Zint Barcode Studio User Manual Zint Barcode Generator and Zint Barcode Studio User Manual
Version 2.15.0.9 Version 2.15.0.9
April 2025 August 2025
******************************************************************************* *******************************************************************************
* For reference the following is a text-only version of the Zint manual, * * 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 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 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. Additional options are available which are specific to certain symbologies.
These may, for example, control the amount of error correction data or the size These may, for example, control the amount of error correction data or the size