QRCODE: fix out-of-bounds crash due to incorrect mode costings for

GS1 percents in `qr_in_alpha()`, ticket #300, props Andre Maute;
  also defensively re-calc version 40 mode to prevent possible
  further crashes
common: move `debug_print_escape()` from library to common
This commit is contained in:
gitlost
2023-11-30 09:12:11 +00:00
parent db92c7de57
commit 888db0bf00
13 changed files with 445 additions and 205 deletions

View File

@ -677,20 +677,6 @@ static int reduced_charset(struct zint_symbol *symbol, struct zint_seg segs[], c
return error_number;
}
/* Helper for ZINT_DEBUG_PRINT to put all but graphical ASCII in angle brackets */
static void debug_print_escape(const unsigned char *source, const int first_len, char *buf) {
int i, j = 0;
for (i = 0; i < first_len; i++) {
const unsigned char ch = source[i];
if (ch < 32 || ch >= 127) {
j += sprintf(buf + j, "<%03o>", ch & 0xFF);
} else {
buf[j++] = ch;
}
}
buf[j] = '\0';
}
#if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic pop
#endif