DBAR_OMN/DBAR_LTD/DBAR_STK/DBAR_OMNSTK: prefix raw_segs with

implicit "01" prefix (see ZXing-C++ issue 883);
  allow and ignore prefixes "01", "[01]" and "(01)" if check digit
  given (ticket #333, props Axel Waggershauser);
CODE128/PDF417: suppress some clang-tidy-20.1 warnings
general: add `ZUCP()`, `ZCUCP()`, `ZCCP()` macro shorthands to
  cast away char pointer signedness
This commit is contained in:
gitlost 2025-04-05 00:19:13 +01:00
parent 01c9b82504
commit 789e049945
7 changed files with 182 additions and 129 deletions

View file

@ -299,6 +299,15 @@ INTERNAL int dbar_omn_cc(struct zint_symbol *symbol, unsigned char source[], int
int widths[4];
const int raw_text = symbol->output_options & BARCODE_RAW_TEXT;
/* Allow and ignore any AI prefix, but only if have check digit */
if (length == 18 && (memcmp(source, "[01]", 4) == 0 || memcmp(source, "(01)", 4) == 0)) {
source += 4;
length -= 4;
/* Likewise initial '01', if have check digit */
} else if (length == 16 && source[0] == '0' && source[1] == '1') {
source += 2;
length -= 2;
}
if (length > 14) { /* Allow check digit to be specified (will be verified and ignored) */
return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 380, "Input length %d too long (maximum 14)", length);
}
@ -617,8 +626,8 @@ INTERNAL int dbar_omn_cc(struct zint_symbol *symbol, unsigned char source[], int
if (raw_text) {
unsigned char buf[14];
if (rt_cpy(symbol, dbar_gtin14(source, length, buf), 14)) {
return ZINT_ERROR_MEMORY; /* `rt_cpy()` only fails with OOM */
if (rt_cpy_cat(symbol, ZCUCP("01"), 2, '\xFF' /*none*/, dbar_gtin14(source, length, buf), 14)) {
return ZINT_ERROR_MEMORY; /* `rt_cpy_cat()` only fails with OOM */
}
}
@ -643,6 +652,15 @@ INTERNAL int dbar_ltd_cc(struct zint_symbol *symbol, unsigned char source[], int
int widths[7];
const int raw_text = symbol->output_options & BARCODE_RAW_TEXT;
/* Allow and ignore any AI prefix, but only if have check digit */
if (length == 18 && (memcmp(source, "[01]", 4) == 0 || memcmp(source, "(01)", 4) == 0)) {
source += 4;
length -= 4;
/* Likewise initial '01', if have check digit */
} else if (length == 16 && source[0] == '0' && source[1] == '1') {
source += 2;
length -= 2;
}
if (length > 14) { /* Allow check digit to be specified (will be verified and ignored) */
return errtxtf(ZINT_ERROR_TOO_LONG, symbol, 382, "Input length %d too long (maximum 14)", length);
}
@ -799,8 +817,8 @@ INTERNAL int dbar_ltd_cc(struct zint_symbol *symbol, unsigned char source[], int
if (raw_text) {
unsigned char buf[14];
if (rt_cpy(symbol, dbar_gtin14(source, length, buf), 14)) {
return ZINT_ERROR_MEMORY; /* `rt_cpy()` only fails with OOM */
if (rt_cpy_cat(symbol, ZCUCP("01"), 2, '\xFF' /*none*/, dbar_gtin14(source, length, buf), 14)) {
return ZINT_ERROR_MEMORY; /* `rt_cpy_cat()` only fails with OOM */
}
}