mirror of
https://git.code.sf.net/p/zint/code
synced 2025-12-18 10:27:09 +00:00
Add text_length (length of text) to zint_symbol, and new
`BARCODE_PLAIN_HRT` option for `output_options` - for use primarily by ZXing-C++ but may be generally useful; centralize setting of HRT using new common `hrt_cpy_nochk()` etc. routines to ensure `text_length` always set PLESSEY: add show default check characters option CODE32: ignore `option_2` (check digit options) PZN: ignore `option_2` (check digit options) except when indicates PZN7 only DPD: exclude DEL from ident tag also out_maybe_mkdir: fix `utf8_to_wide()` return (Windows only) general: replace use of `strcpy()` etc. (except for test suite) with `memcpy()`, `hrt_()` etc. in lib & `cpy_str()` etc. in CLI & `cpy_bytearray_left()` in backend_qt clang-tidy: update README reflecting above backend_tcl: use sizeof(primary) to check length; tabs -> spaces general: various code fiddling docs: pandoc 3.6.2 -> 3.6.3
This commit is contained in:
@@ -118,8 +118,11 @@ INTERNAL int auspost(struct zint_symbol *symbol, unsigned char source[], int len
|
||||
|
||||
char data_pattern[200];
|
||||
char *d = data_pattern;
|
||||
char fcc[3] = {0}, dpid[10];
|
||||
char localstr[30];
|
||||
unsigned char fcc[2] = {0}; /* Suppress clang-tidy warning clang-analyzer-core.UndefinedBinaryOperatorResult */
|
||||
unsigned char dpid[9];
|
||||
unsigned char local_source[30];
|
||||
int zeroes = 0;
|
||||
const int plain_hrt = symbol->output_options & BARCODE_PLAIN_HRT;
|
||||
|
||||
/* Do all of the length checking first to avoid stack smashing */
|
||||
if (symbol->symbology == BARCODE_AUSPOST) {
|
||||
@@ -137,19 +140,17 @@ INTERNAL int auspost(struct zint_symbol *symbol, unsigned char source[], int len
|
||||
"Invalid character at position %d in input (alphanumerics, space and \"#\" only)", i);
|
||||
}
|
||||
|
||||
localstr[0] = '\0';
|
||||
|
||||
if (symbol->symbology == BARCODE_AUSPOST) {
|
||||
/* Format control code (FCC) */
|
||||
switch (length) {
|
||||
case 8:
|
||||
strcpy(fcc, "11");
|
||||
memcpy(fcc, "11", 2);
|
||||
break;
|
||||
case 13:
|
||||
strcpy(fcc, "59");
|
||||
memcpy(fcc, "59", 2);
|
||||
break;
|
||||
case 16:
|
||||
strcpy(fcc, "59");
|
||||
memcpy(fcc, "59", 2);
|
||||
if ((i = not_sane(NEON_F, source, length))) {
|
||||
return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 402,
|
||||
"Invalid character at position %d in input (digits only for FCC 59 length 16)",
|
||||
@@ -157,10 +158,10 @@ INTERNAL int auspost(struct zint_symbol *symbol, unsigned char source[], int len
|
||||
}
|
||||
break;
|
||||
case 18:
|
||||
strcpy(fcc, "62");
|
||||
memcpy(fcc, "62", 2);
|
||||
break;
|
||||
case 23:
|
||||
strcpy(fcc, "62");
|
||||
memcpy(fcc, "62", 2);
|
||||
if ((i = not_sane(NEON_F, source, length))) {
|
||||
return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 406,
|
||||
"Invalid character at position %d in input (digits only for FCC 62 length 23)",
|
||||
@@ -169,32 +170,29 @@ INTERNAL int auspost(struct zint_symbol *symbol, unsigned char source[], int len
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
int zeroes;
|
||||
switch (symbol->symbology) {
|
||||
case BARCODE_AUSREPLY: strcpy(fcc, "45");
|
||||
case BARCODE_AUSREPLY: memcpy(fcc, "45", 2);
|
||||
break;
|
||||
case BARCODE_AUSROUTE: strcpy(fcc, "87");
|
||||
case BARCODE_AUSROUTE: memcpy(fcc, "87", 2);
|
||||
break;
|
||||
case BARCODE_AUSREDIRECT: strcpy(fcc, "92");
|
||||
case BARCODE_AUSREDIRECT: memcpy(fcc, "92", 2);
|
||||
break;
|
||||
}
|
||||
|
||||
/* Add leading zeros as required */
|
||||
zeroes = 8 - length;
|
||||
memset(localstr, '0', zeroes);
|
||||
localstr[zeroes] = '\0';
|
||||
memset(local_source, '0', zeroes);
|
||||
}
|
||||
|
||||
if (symbol->debug & ZINT_DEBUG_PRINT) {
|
||||
printf("AUSPOST FCC: %s\n", fcc);
|
||||
printf("AUSPOST FCC: %.2s\n", fcc);
|
||||
}
|
||||
|
||||
ustrncat(localstr, source, length);
|
||||
h = (int) strlen(localstr);
|
||||
memcpy(local_source + zeroes, source, length);
|
||||
length += zeroes;
|
||||
/* Verify that the first 8 characters are numbers */
|
||||
memcpy(dpid, localstr, 8);
|
||||
dpid[8] = '\0';
|
||||
if ((i = not_sane(NEON_F, (const unsigned char *) dpid, 8))) {
|
||||
memcpy(dpid, local_source, 8);
|
||||
if ((i = not_sane(NEON_F, dpid, 8))) {
|
||||
return errtxtf(ZINT_ERROR_INVALID_DATA, symbol, 405,
|
||||
"Invalid character at position %d in DPID (first 8 characters) (digits only)", i);
|
||||
}
|
||||
@@ -214,14 +212,14 @@ INTERNAL int auspost(struct zint_symbol *symbol, unsigned char source[], int len
|
||||
}
|
||||
|
||||
/* Customer Information */
|
||||
if (h > 8) {
|
||||
if ((h == 13) || (h == 18)) {
|
||||
for (reader = 8; reader < h; reader++, d += 3) {
|
||||
memcpy(d, AusCTable[posn(GDSET, localstr[reader])], 3);
|
||||
if (length > 8) {
|
||||
if ((length == 13) || (length == 18)) {
|
||||
for (reader = 8; reader < length; reader++, d += 3) {
|
||||
memcpy(d, AusCTable[posn(GDSET, local_source[reader])], 3);
|
||||
}
|
||||
} else if ((h == 16) || (h == 23)) {
|
||||
for (reader = 8; reader < h; reader++, d += 2) {
|
||||
memcpy(d, AusNTable[localstr[reader] - '0'], 2);
|
||||
} else if ((length == 16) || (length == 23)) {
|
||||
for (reader = 8; reader < length; reader++, d += 2) {
|
||||
memcpy(d, AusNTable[local_source[reader] - '0'], 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -279,6 +277,11 @@ INTERNAL int auspost(struct zint_symbol *symbol, unsigned char source[], int len
|
||||
symbol->rows = 3;
|
||||
symbol->width = writer - 1;
|
||||
|
||||
if (plain_hrt) {
|
||||
hrt_cpy_nochk(symbol, fcc, 2);
|
||||
hrt_cat_nochk(symbol, local_source, length);
|
||||
}
|
||||
|
||||
return error_number;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user