mirror of
https://git.code.sf.net/p/zint/code
synced 2026-01-08 04:21:59 +00:00
general: prefix all INTERNAL funcs/tables with zint_, except
those in "backend/common.h", which are prefixed by `z_` - makes symbol clashes more unlikely when zint is statically linked (ticket #337, props Ulrich Becker) DOTCODE: fix padding allowance (10 -> 52 - probable max 35) to cover cases with large no. of columns requested and little data, to prevent `codeword_array` buffer overflow AZTEC/CODEONE: some code fiddling general_field: prefix defines with `GF_`, shorten static funcs prefix `general_field_` -> `gf_`
This commit is contained in:
@@ -69,32 +69,32 @@ static int dx_parse_code(struct zint_symbol *symbol, const unsigned char *source
|
||||
|
||||
/* All codes should start with a digit*/
|
||||
if (!z_isdigit(source[0])) {
|
||||
return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 970,
|
||||
return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 970,
|
||||
"Invalid first character \"%c\", DX code should start with a number", source[0]);
|
||||
}
|
||||
|
||||
/* Check if there is the '/' separator, which indicates the frame number is present. */
|
||||
dx_length = posn((const char *) source, '/');
|
||||
dx_length = z_posn(ZCCP(source), '/');
|
||||
if (dx_length != -1) {
|
||||
/* Split the DX information from the frame number */
|
||||
const char *frame_start;
|
||||
int frame_info_len;
|
||||
if (dx_length > DX_MAX_DX_INFO_LENGTH) {
|
||||
return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 971,
|
||||
return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 971,
|
||||
"DX information length %d too long (maximum " DX_MAX_DX_INFO_MAX_STR ")", dx_length);
|
||||
}
|
||||
memcpy(dx_info, source, dx_length);
|
||||
frame_start = (const char *) source + dx_length + 1;
|
||||
frame_start = ZCCP(source + dx_length + 1);
|
||||
frame_info_len = (int) strlen(frame_start);
|
||||
if (frame_info_len > DX_MAX_FRAME_INFO_LENGTH) {
|
||||
return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 972,
|
||||
return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 972,
|
||||
"Frame number part length %d too long (maximum " DX_MAX_FRAME_INFO_MAX_STR ")", frame_info_len);
|
||||
}
|
||||
memcpy(frame_info, frame_start, frame_info_len);
|
||||
*has_frame_info = 1;
|
||||
to_upper((unsigned char *) frame_info, frame_info_len);
|
||||
if (not_sane(IS_UPR_F | IS_NUM_F | IS_MNS_F, (const unsigned char *) frame_info, frame_info_len)) {
|
||||
return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 973,
|
||||
z_to_upper(ZUCP(frame_info), frame_info_len);
|
||||
if (z_not_sane(IS_UPR_F | IS_NUM_F | IS_MNS_F, ZCUCP(frame_info), frame_info_len)) {
|
||||
return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 973,
|
||||
"Frame number \"%s\" is invalid (expected digits, optionally followed by a single \"A\")",
|
||||
frame_info);
|
||||
}
|
||||
@@ -102,14 +102,14 @@ static int dx_parse_code(struct zint_symbol *symbol, const unsigned char *source
|
||||
/* No "/" found, store the entire input in dx_info */
|
||||
dx_length = length;
|
||||
if (dx_length > DX_MAX_DX_INFO_LENGTH) {
|
||||
return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 974,
|
||||
return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 974,
|
||||
"DX information length %d too long (maximum " DX_MAX_DX_INFO_MAX_STR ")", dx_length);
|
||||
}
|
||||
memcpy(dx_info, source, dx_length);
|
||||
}
|
||||
|
||||
if ((i = not_sane(IS_NUM_F | IS_MNS_F, (const unsigned char *) dx_info, dx_length))) {
|
||||
return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 975,
|
||||
if ((i = z_not_sane(IS_NUM_F | IS_MNS_F, ZCUCP(dx_info), dx_length))) {
|
||||
return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 975,
|
||||
"Invalid character at position %d in DX info (digits and \"-\" character only)", i);
|
||||
}
|
||||
|
||||
@@ -118,20 +118,20 @@ static int dx_parse_code(struct zint_symbol *symbol, const unsigned char *source
|
||||
if (strchr(dx_info, '-')) {
|
||||
/* DX code parts 1 and 2 are given directly, separated by a '-'. Eg: "79-7" */
|
||||
if (debug_print) printf("DX code 1 and 2 are separated by a dash \"-\"\n");
|
||||
if (chr_cnt((const unsigned char *) dx_info, dx_length, '-') > 1) {
|
||||
return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 976,
|
||||
if (z_chr_cnt(ZCUCP(dx_info), dx_length, '-') > 1) {
|
||||
return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 976,
|
||||
"The \"-\" is used to separate DX parts 1 and 2, and should be used no more than once");
|
||||
}
|
||||
if (sscanf(dx_info, "%d-%d", &dx_code_1, &dx_code_2) < 2) {
|
||||
return errtxt(ZINT_ERROR_INVALID_DATA, symbol, 977,
|
||||
return z_errtxt(ZINT_ERROR_INVALID_DATA, symbol, 977,
|
||||
"Wrong format for DX parts 1 and 2 (expected format: NNN-NN, digits)");
|
||||
}
|
||||
if (dx_code_1 <= 0 || dx_code_1 > 127) {
|
||||
return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 978, "DX part 1 \"%d\" out of range (1 to 127)",
|
||||
return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 978, "DX part 1 \"%d\" out of range (1 to 127)",
|
||||
dx_code_1);
|
||||
}
|
||||
if (dx_code_2 < 0 || dx_code_2 > 15) {
|
||||
return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 979, "DX part 2 \"%d\" out of range (0 to 15)",
|
||||
return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 979, "DX part 2 \"%d\" out of range (0 to 15)",
|
||||
dx_code_2);
|
||||
}
|
||||
} else {
|
||||
@@ -140,8 +140,9 @@ static int dx_parse_code(struct zint_symbol *symbol, const unsigned char *source
|
||||
if (debug_print) printf("No \"-\" separator, computing from DX Extract (4 digits) or DX Full (6 digits)\n");
|
||||
assert(dx_length <= 6); /* I.e. DX_MAX_DX_INFO_LENGTH, guaranteed above */
|
||||
if (dx_length == 5) {
|
||||
return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 980,
|
||||
"DX number \"%s\" is incorrect; expected 4 digits (DX extract) or 6 digits (DX full)", dx_info);
|
||||
return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 980,
|
||||
"DX number \"%s\" is incorrect; expected 4 digits (DX extract) or 6 digits (DX full)",
|
||||
dx_info);
|
||||
}
|
||||
if (dx_length == 6) {
|
||||
if (debug_print) {
|
||||
@@ -154,10 +155,10 @@ static int dx_parse_code(struct zint_symbol *symbol, const unsigned char *source
|
||||
dx_length = 4;
|
||||
}
|
||||
/* Compute the DX parts 1 and 2 from the DX extract */
|
||||
dx_extract = to_int((const unsigned char *) dx_info, dx_length);
|
||||
dx_extract = z_to_int(ZCUCP(dx_info), dx_length);
|
||||
assert(dx_extract != -1); /* All digits (no hyphen) & length 6 max - can't fail */
|
||||
if (dx_extract < 16 || dx_extract > 2047) {
|
||||
return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 981, "DX extract \"%d\" out of range (16 to 2047)",
|
||||
return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 981, "DX extract \"%d\" out of range (16 to 2047)",
|
||||
dx_extract);
|
||||
}
|
||||
if (debug_print) printf("Computed DX extract: %04d\n", dx_extract);
|
||||
@@ -173,7 +174,7 @@ static int dx_parse_code(struct zint_symbol *symbol, const unsigned char *source
|
||||
if (*has_frame_info) {
|
||||
int ret_sscanf, n;
|
||||
if (strlen(frame_info) < 1) {
|
||||
return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 982,
|
||||
return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 982,
|
||||
"Frame number indicator \"/\" at position %d, but frame number is empty",
|
||||
dx_length + 1);
|
||||
}
|
||||
@@ -194,12 +195,12 @@ static int dx_parse_code(struct zint_symbol *symbol, const unsigned char *source
|
||||
|
||||
ret_sscanf = sscanf(frame_info, "%d%c%n", &frame_number, &half_frame_flag, &n);
|
||||
if (ret_sscanf < 1 || (ret_sscanf == 2 && frame_info[n] != '\0')) {
|
||||
return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 983,
|
||||
return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 983,
|
||||
"Frame number \"%s\" is invalid (expected digits, optionally followed by a single \"A\")",
|
||||
frame_info);
|
||||
}
|
||||
if (frame_number < 0 || frame_number > 63) {
|
||||
return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 984, "Frame number \"%d\" out of range (0 to 63)",
|
||||
return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 984, "Frame number \"%d\" out of range (0 to 63)",
|
||||
frame_number);
|
||||
}
|
||||
if (debug_print) {
|
||||
@@ -209,18 +210,18 @@ static int dx_parse_code(struct zint_symbol *symbol, const unsigned char *source
|
||||
|
||||
/* Build the binary output */
|
||||
memcpy(binary_output, "101010", 6); /* Start pattern */
|
||||
bp = bin_append_posn(dx_code_1, 7, binary_output, 6);
|
||||
bp = z_bin_append_posn(dx_code_1, 7, binary_output, 6);
|
||||
binary_output[bp++] = '0'; /* Separator between DX part 1 and DX part 2 */
|
||||
bp = bin_append_posn(dx_code_2, 4, binary_output, bp);
|
||||
bp = z_bin_append_posn(dx_code_2, 4, binary_output, bp);
|
||||
if (*has_frame_info) {
|
||||
bp = bin_append_posn(frame_number, 6, binary_output, bp);
|
||||
to_upper((unsigned char *) &half_frame_flag, 1);
|
||||
bp = z_bin_append_posn(frame_number, 6, binary_output, bp);
|
||||
z_to_upper(ZUCP(&half_frame_flag), 1);
|
||||
if (half_frame_flag == 'A') {
|
||||
if (debug_print) printf("%-*s'%c'\t-> 1\n", DX_DEBUG_STR_LEN, "Half frame flag:", half_frame_flag);
|
||||
binary_output[bp++] = '1'; /* Half-frame is set */
|
||||
} else {
|
||||
if (half_frame_flag) {
|
||||
return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 985,
|
||||
return z_errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 985,
|
||||
"Frame number \"%s\" is invalid (expected digits, optionally followed by a single \"A\")",
|
||||
frame_info);
|
||||
}
|
||||
@@ -246,15 +247,15 @@ static int dx_parse_code(struct zint_symbol *symbol, const unsigned char *source
|
||||
|
||||
*output_length = bp;
|
||||
|
||||
if (raw_text && rt_printf_256(symbol, (*has_frame_info ? "%d-%d%s%s" : "%d-%d"), dx_code_1, dx_code_2, "/",
|
||||
if (raw_text && z_rt_printf_256(symbol, (*has_frame_info ? "%d-%d%s%s" : "%d-%d"), dx_code_1, dx_code_2, "/",
|
||||
frame_info)) {
|
||||
return ZINT_ERROR_MEMORY; /* `rt_printf_256()` only fails with OOM */
|
||||
return ZINT_ERROR_MEMORY; /* `z_rt_printf_256()` only fails with OOM */
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
INTERNAL int dxfilmedge(struct zint_symbol *symbol, unsigned char source[], int length) {
|
||||
INTERNAL int zint_dxfilmedge(struct zint_symbol *symbol, unsigned char source[], int length) {
|
||||
int i;
|
||||
int writer = 0;
|
||||
int error_number;
|
||||
@@ -269,7 +270,7 @@ INTERNAL int dxfilmedge(struct zint_symbol *symbol, unsigned char source[], int
|
||||
const int debug_print = symbol->debug & ZINT_DEBUG_PRINT;
|
||||
|
||||
if (length > 10) {
|
||||
return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 986, "Input length %d too long (maximum 10)", length);
|
||||
return z_errtxtf(ZINT_ERROR_TOO_LONG, symbol, 986, "Input length %d too long (maximum 10)", length);
|
||||
}
|
||||
|
||||
error_number = dx_parse_code(symbol, source, length, binary_output, &output_length, &has_frame_info);
|
||||
@@ -290,9 +291,9 @@ INTERNAL int dxfilmedge(struct zint_symbol *symbol, unsigned char source[], int
|
||||
/* First row: clock pattern */
|
||||
for (i = 0; i < output_length; i++) {
|
||||
if (clock_pattern[i] == '1') {
|
||||
set_module(symbol, 0, writer);
|
||||
z_set_module(symbol, 0, writer);
|
||||
} else if (clock_pattern[i] == '0') {
|
||||
unset_module(symbol, 0, writer);
|
||||
z_unset_module(symbol, 0, writer);
|
||||
}
|
||||
writer++;
|
||||
}
|
||||
@@ -303,9 +304,9 @@ INTERNAL int dxfilmedge(struct zint_symbol *symbol, unsigned char source[], int
|
||||
/* Second row: data signal */
|
||||
for (i = 0; i < output_length; i++) {
|
||||
if (binary_output[i] == '1') {
|
||||
set_module(symbol, 1, writer);
|
||||
z_set_module(symbol, 1, writer);
|
||||
} else if (binary_output[i] == '0') {
|
||||
unset_module(symbol, 1, writer);
|
||||
z_unset_module(symbol, 1, writer);
|
||||
}
|
||||
writer++;
|
||||
}
|
||||
@@ -319,11 +320,11 @@ INTERNAL int dxfilmedge(struct zint_symbol *symbol, unsigned char source[], int
|
||||
/* AFAIK There is no standard on minimum and maximum height, so we stay close to the measurements */
|
||||
const float min_row_height = 2.2f;
|
||||
const float max_height = 7.5f;
|
||||
error_number = set_height(symbol, min_row_height, default_height, max_height, 0 /*no_errtxt*/);
|
||||
error_number = z_set_height(symbol, min_row_height, default_height, max_height, 0 /*no_errtxt*/);
|
||||
} else {
|
||||
/* Using compliant height as default as no backwards compatibility to consider */
|
||||
const float default_height = 6.0f;
|
||||
(void) set_height(symbol, 0.0f, default_height, 0.0f, 1 /*no_errtxt*/);
|
||||
(void) z_set_height(symbol, 0.0f, default_height, 0.0f, 1 /*no_errtxt*/);
|
||||
}
|
||||
|
||||
return error_number;
|
||||
|
||||
Reference in New Issue
Block a user