mirror of
https://github.com/zint/zint
synced 2024-11-16 20:57:25 +13:00
malloc/calloc: check for NULL always (11.1.0 gcc -fanalyzer -c backend/*.c)
ZBarcode_Encode: don't reinit symbol->outfile, props Alonso Schaich frontend/test_args: skip long filename tests on Windows, props Alonso Schaich
This commit is contained in:
parent
8c419ab4fb
commit
368633bda4
@ -1198,13 +1198,20 @@ INTERNAL int aztec(struct zint_symbol *symbol, unsigned char source[], int lengt
|
|||||||
rs_encode_uint(&rs, data_blocks, data_part, ecc_part);
|
rs_encode_uint(&rs, data_blocks, data_part, ecc_part);
|
||||||
break;
|
break;
|
||||||
case 10:
|
case 10:
|
||||||
rs_uint_init_gf(&rs_uint, 0x409, 1023);
|
if (!rs_uint_init_gf(&rs_uint, 0x409, 1023)) { /* Can fail on malloc() */
|
||||||
|
strcpy(symbol->errtxt, "500: Insufficient memory for Reed-Solomon log tables");
|
||||||
|
return ZINT_ERROR_MEMORY;
|
||||||
|
}
|
||||||
rs_uint_init_code(&rs_uint, ecc_blocks, 1);
|
rs_uint_init_code(&rs_uint, ecc_blocks, 1);
|
||||||
rs_uint_encode(&rs_uint, data_blocks, data_part, ecc_part);
|
rs_uint_encode(&rs_uint, data_blocks, data_part, ecc_part);
|
||||||
rs_uint_free(&rs_uint);
|
rs_uint_free(&rs_uint);
|
||||||
break;
|
break;
|
||||||
case 12:
|
case 12:
|
||||||
rs_uint_init_gf(&rs_uint, 0x1069, 4095);
|
if (!rs_uint_init_gf(&rs_uint, 0x1069, 4095)) { /* Can fail on malloc() */
|
||||||
|
/* Note using AUSPOST error nos range as out of 50x ones & 51x taken by CODEONE */
|
||||||
|
strcpy(symbol->errtxt, "400: Insufficient memory for Reed-Solomon log tables");
|
||||||
|
return ZINT_ERROR_MEMORY;
|
||||||
|
}
|
||||||
rs_uint_init_code(&rs_uint, ecc_blocks, 1);
|
rs_uint_init_code(&rs_uint, ecc_blocks, 1);
|
||||||
rs_uint_encode(&rs_uint, data_blocks, data_part, ecc_part);
|
rs_uint_encode(&rs_uint, data_blocks, data_part, ecc_part);
|
||||||
rs_uint_free(&rs_uint);
|
rs_uint_free(&rs_uint);
|
||||||
|
@ -620,7 +620,13 @@ INTERNAL int emf_plot(struct zint_symbol *symbol, int rotate_angle) {
|
|||||||
assert(str->length > 0);
|
assert(str->length > 0);
|
||||||
utfle_len = utfle_length(str->text, str->length);
|
utfle_len = utfle_length(str->text, str->length);
|
||||||
bumped_len = bump_up(utfle_len) * 2;
|
bumped_len = bump_up(utfle_len) * 2;
|
||||||
this_string[this_text] = (unsigned char *) malloc(bumped_len);
|
if (!(this_string[this_text] = (unsigned char *) malloc(bumped_len))) {
|
||||||
|
for (i = 0; i < this_text; i++) {
|
||||||
|
free(this_string[i]);
|
||||||
|
}
|
||||||
|
strcpy(symbol->errtxt, "641: Insufficient memory for EMF string buffer");
|
||||||
|
return ZINT_ERROR_MEMORY;
|
||||||
|
}
|
||||||
memset(this_string[this_text], 0, bumped_len);
|
memset(this_string[this_text], 0, bumped_len);
|
||||||
text[this_text].type = 0x00000054; // EMR_EXTTEXTOUTW
|
text[this_text].type = 0x00000054; // EMR_EXTTEXTOUTW
|
||||||
text[this_text].size = 76 + bumped_len;
|
text[this_text].size = 76 + bumped_len;
|
||||||
|
@ -1000,7 +1000,7 @@ int ZBarcode_Encode(struct zint_symbol *symbol, const unsigned char *source, int
|
|||||||
" in_length: %d, First 10 source: \"%.10s\", First 10 primary: \"%.10s\"\n",
|
" in_length: %d, First 10 source: \"%.10s\", First 10 primary: \"%.10s\"\n",
|
||||||
symbol->symbology, symbol->input_mode, symbol->eci, symbol->option_1, symbol->option_2,
|
symbol->symbology, symbol->input_mode, symbol->eci, symbol->option_1, symbol->option_2,
|
||||||
symbol->option_3, symbol->scale, symbol->output_options, symbol->fgcolour, symbol->bgcolour,
|
symbol->option_3, symbol->scale, symbol->output_options, symbol->fgcolour, symbol->bgcolour,
|
||||||
in_length, source, symbol->primary);
|
in_length, source ? (const char *) source : "<NULL>", symbol->primary);
|
||||||
}
|
}
|
||||||
|
|
||||||
warn_number = 0;
|
warn_number = 0;
|
||||||
@ -1021,14 +1021,6 @@ int ZBarcode_Encode(struct zint_symbol *symbol, const unsigned char *source, int
|
|||||||
return error_tag(symbol->errtxt, ZINT_ERROR_TOO_LONG);
|
return error_tag(symbol->errtxt, ZINT_ERROR_TOO_LONG);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*symbol->outfile == '\0') {
|
|
||||||
#ifdef NO_PNG
|
|
||||||
strcpy(symbol->outfile, "out.gif");
|
|
||||||
#else
|
|
||||||
strcpy(symbol->outfile, "out.png");
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
/* First check the symbology field */
|
/* First check the symbology field */
|
||||||
if (!ZBarcode_ValidID(symbol->symbology)) {
|
if (!ZBarcode_ValidID(symbol->symbology)) {
|
||||||
if (symbol->symbology < 1) {
|
if (symbol->symbology < 1) {
|
||||||
|
@ -66,7 +66,10 @@ INTERNAL int plessey(struct zint_symbol *symbol, unsigned char source[], int len
|
|||||||
strcpy(symbol->errtxt, "371: Invalid characters in data");
|
strcpy(symbol->errtxt, "371: Invalid characters in data");
|
||||||
return error_number;
|
return error_number;
|
||||||
}
|
}
|
||||||
checkptr = (unsigned char *) calloc(1, length * 4 + 8);
|
if (!(checkptr = (unsigned char *) calloc(1, length * 4 + 8))) {
|
||||||
|
strcpy(symbol->errtxt, "373: Insufficient memory for check digit CRC buffer");
|
||||||
|
return ZINT_ERROR_MEMORY;
|
||||||
|
}
|
||||||
|
|
||||||
/* Start character */
|
/* Start character */
|
||||||
strcpy(dest, "31311331");
|
strcpy(dest, "31311331");
|
||||||
|
@ -191,14 +191,22 @@ INTERNAL void rs_encode_uint(const rs_t *rs, const int datalen, const unsigned i
|
|||||||
// Then call rs_uint_free(&rs_uint) to free the log tables.
|
// Then call rs_uint_free(&rs_uint) to free the log tables.
|
||||||
|
|
||||||
/* `logmod` (field characteristic) will be 2**bitlength - 1, eg 1023 for bitlength 10, 4095 for bitlength 12 */
|
/* `logmod` (field characteristic) will be 2**bitlength - 1, eg 1023 for bitlength 10, 4095 for bitlength 12 */
|
||||||
INTERNAL void rs_uint_init_gf(rs_uint_t *rs_uint, const unsigned int prime_poly, const int logmod) {
|
INTERNAL int rs_uint_init_gf(rs_uint_t *rs_uint, const unsigned int prime_poly, const int logmod) {
|
||||||
int b, p, v;
|
int b, p, v;
|
||||||
unsigned int *logt, *alog;
|
unsigned int *logt, *alog;
|
||||||
|
|
||||||
b = logmod + 1;
|
b = logmod + 1;
|
||||||
|
|
||||||
logt = (unsigned int *) malloc(sizeof(unsigned int) * b);
|
rs_uint->logt = NULL;
|
||||||
alog = (unsigned int *) malloc(sizeof(unsigned int) * b * 2);
|
rs_uint->alog = NULL;
|
||||||
|
|
||||||
|
if (!(logt = (unsigned int *) malloc(sizeof(unsigned int) * b))) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (!(alog = (unsigned int *) malloc(sizeof(unsigned int) * b * 2))) {
|
||||||
|
free(logt);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
// Calculate the log/alog tables
|
// Calculate the log/alog tables
|
||||||
for (p = 1, v = 0; v < logmod; v++) {
|
for (p = 1, v = 0; v < logmod; v++) {
|
||||||
@ -211,6 +219,7 @@ INTERNAL void rs_uint_init_gf(rs_uint_t *rs_uint, const unsigned int prime_poly,
|
|||||||
}
|
}
|
||||||
rs_uint->logt = logt;
|
rs_uint->logt = logt;
|
||||||
rs_uint->alog = alog;
|
rs_uint->alog = alog;
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
INTERNAL void rs_uint_init_code(rs_uint_t *rs_uint, const int nsym, int index) {
|
INTERNAL void rs_uint_init_code(rs_uint_t *rs_uint, const int nsym, int index) {
|
||||||
@ -219,6 +228,9 @@ INTERNAL void rs_uint_init_code(rs_uint_t *rs_uint, const int nsym, int index) {
|
|||||||
const unsigned int *alog = rs_uint->alog;
|
const unsigned int *alog = rs_uint->alog;
|
||||||
unsigned short *rspoly = rs_uint->rspoly;
|
unsigned short *rspoly = rs_uint->rspoly;
|
||||||
|
|
||||||
|
if (logt == NULL || alog == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
rs_uint->nsym = nsym;
|
rs_uint->nsym = nsym;
|
||||||
|
|
||||||
rspoly[0] = 1;
|
rspoly[0] = 1;
|
||||||
@ -234,7 +246,8 @@ INTERNAL void rs_uint_init_code(rs_uint_t *rs_uint, const int nsym, int index) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
INTERNAL void rs_uint_encode(const rs_uint_t *rs_uint, const int datalen, const unsigned int *data, unsigned int *res) {
|
INTERNAL void rs_uint_encode(const rs_uint_t *rs_uint, const int datalen, const unsigned int *data,
|
||||||
|
unsigned int *res) {
|
||||||
int i, k;
|
int i, k;
|
||||||
const unsigned int *logt = rs_uint->logt;
|
const unsigned int *logt = rs_uint->logt;
|
||||||
const unsigned int *alog = rs_uint->alog;
|
const unsigned int *alog = rs_uint->alog;
|
||||||
@ -242,6 +255,9 @@ INTERNAL void rs_uint_encode(const rs_uint_t *rs_uint, const int datalen, const
|
|||||||
const int nsym = rs_uint->nsym;
|
const int nsym = rs_uint->nsym;
|
||||||
|
|
||||||
memset(res, 0, sizeof(unsigned int) * nsym);
|
memset(res, 0, sizeof(unsigned int) * nsym);
|
||||||
|
if (logt == NULL || alog == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
for (i = 0; i < datalen; i++) {
|
for (i = 0; i < datalen; i++) {
|
||||||
unsigned int m = res[nsym - 1] ^ data[i];
|
unsigned int m = res[nsym - 1] ^ data[i];
|
||||||
if (m) {
|
if (m) {
|
||||||
@ -261,6 +277,12 @@ INTERNAL void rs_uint_encode(const rs_uint_t *rs_uint, const int datalen, const
|
|||||||
}
|
}
|
||||||
|
|
||||||
INTERNAL void rs_uint_free(rs_uint_t *rs_uint) {
|
INTERNAL void rs_uint_free(rs_uint_t *rs_uint) {
|
||||||
free(rs_uint->logt);
|
if (rs_uint->logt) {
|
||||||
free(rs_uint->alog);
|
free(rs_uint->logt);
|
||||||
|
rs_uint->logt = NULL;
|
||||||
|
}
|
||||||
|
if (rs_uint->alog) {
|
||||||
|
free(rs_uint->alog);
|
||||||
|
rs_uint->alog = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -58,9 +58,10 @@ INTERNAL void rs_encode(const rs_t *rs, const int datalen, const unsigned char *
|
|||||||
INTERNAL void rs_encode_uint(const rs_t *rs, const int datalen, const unsigned int *data, unsigned int *res);
|
INTERNAL void rs_encode_uint(const rs_t *rs, const int datalen, const unsigned int *data, unsigned int *res);
|
||||||
/* No free needed as log tables static */
|
/* No free needed as log tables static */
|
||||||
|
|
||||||
INTERNAL void rs_uint_init_gf(rs_uint_t *rs_uint, const unsigned int prime_poly, const int logmod);
|
INTERNAL int rs_uint_init_gf(rs_uint_t *rs_uint, const unsigned int prime_poly, const int logmod);
|
||||||
INTERNAL void rs_uint_init_code(rs_uint_t *rs_uint, const int nsym, int index);
|
INTERNAL void rs_uint_init_code(rs_uint_t *rs_uint, const int nsym, int index);
|
||||||
INTERNAL void rs_uint_encode(const rs_uint_t *rs_uint, const int datalen, const unsigned int *data, unsigned int *res);
|
INTERNAL void rs_uint_encode(const rs_uint_t *rs_uint, const int datalen, const unsigned int *data,
|
||||||
|
unsigned int *res);
|
||||||
INTERNAL void rs_uint_free(rs_uint_t *rs_uint);
|
INTERNAL void rs_uint_free(rs_uint_t *rs_uint);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -185,6 +185,7 @@ static void test_input_mode(int index, int debug) {
|
|||||||
static void test_escape_char_process(int index, int generate, int debug) {
|
static void test_escape_char_process(int index, int generate, int debug) {
|
||||||
|
|
||||||
struct item {
|
struct item {
|
||||||
|
int symbology;
|
||||||
int input_mode;
|
int input_mode;
|
||||||
int eci;
|
int eci;
|
||||||
char *data;
|
char *data;
|
||||||
@ -195,32 +196,40 @@ static void test_escape_char_process(int index, int generate, int debug) {
|
|||||||
char *comment;
|
char *comment;
|
||||||
};
|
};
|
||||||
struct item data[] = {
|
struct item data[] = {
|
||||||
/* 0*/ { DATA_MODE, -1, "\\0\\E\\a\\b\\t\\n\\v\\f\\r\\e\\G\\R\\x81\\\\", 0, 26, "01 05 08 09 0A 0B 0C 0D E7 D8 7B 1F B6 4D 45 B6 45 7C EF DD 8C 4C 8D 1E D0 55 AD FE A8 52", 0, "" },
|
/* 0*/ { BARCODE_DATAMATRIX, DATA_MODE, -1, "\\0\\E\\a\\b\\t\\n\\v\\f\\r\\e\\G\\R\\x81\\\\", 0, 26, "01 05 08 09 0A 0B 0C 0D E7 D8 7B 1F B6 4D 45 B6 45 7C EF DD 8C 4C 8D 1E D0 55 AD FE A8 52", 0, "" },
|
||||||
/* 1*/ { DATA_MODE, -1, "\\c", ZINT_ERROR_INVALID_DATA, 0, "Error 234: Unrecognised escape character in input data", 0, "" },
|
/* 1*/ { BARCODE_CODABLOCKF, DATA_MODE, -1, "\\0\\E\\a\\b\\t\\n\\v\\f\\r\\e\\G\\R\\x81\\\\", 0, 101, "(45) 67 62 43 40 44 47 48 29 6A 67 62 0B 49 4A 4B 4C 18 6A 67 62 0C 4D 5B 5D 5E 62 6A 67", 0, "" },
|
||||||
/* 2*/ { DATA_MODE, -1, "\\", ZINT_ERROR_INVALID_DATA, 0, "Error 236: Incomplete escape character in input data", 0, "" },
|
/* 2*/ { BARCODE_CODE16K, DATA_MODE, -1, "\\0\\E\\a\\b\\t\\n\\v\\f\\r\\e\\G\\R\\x81\\\\", 0, 70, "(20) 14 64 68 71 72 73 74 75 76 77 91 93 94 101 65 60 103 103 45 61", 0, "" },
|
||||||
/* 3*/ { DATA_MODE, -1, "\\x", ZINT_ERROR_INVALID_DATA, 0, "Error 232: Incomplete escape character in input data", 0, "" },
|
/* 3*/ { BARCODE_DOTCODE, DATA_MODE, -1, "\\0\\E\\a\\b\\t\\n\\v\\f\\r\\e\\G\\R\\x81\\\\", 0, 28, "65 40 44 47 48 49 4A 4B 4C 4D 5B 5D 5E 6E 41 3C", 0, "" },
|
||||||
/* 4*/ { DATA_MODE, -1, "\\x1", ZINT_ERROR_INVALID_DATA, 0, "Error 232: Incomplete escape character in input data", 0, "" },
|
/* 4*/ { BARCODE_GRIDMATRIX, DATA_MODE, -1, "\\0\\E\\a\\b\\t\\n\\v\\f\\r\\e\\G\\R\\x81\\\\", 0, 30, "30 1A 00 02 01 61 00 48 28 16 0C 06 46 63 51 74 05 38 00", 0, "" },
|
||||||
/* 5*/ { DATA_MODE, -1, "\\x1g", ZINT_ERROR_INVALID_DATA, 0, "Error 233: Corrupt escape character in input data", 0, "" },
|
/* 5*/ { BARCODE_HANXIN, DATA_MODE, -1, "\\0\\E\\a\\b\\t\\n\\v\\f\\r\\e\\G\\R\\x81\\\\", 0, 23, "2F 80 10 72 09 28 B3 0D 6F F3 00 20 E8 F4 0A E0 00", 0, "" },
|
||||||
/* 6*/ { DATA_MODE, -1, "\\xA01\\xFF", 0, 12, "EB 21 32 EB 80 D8 49 44 DC 7D 9E 3B", 0, "" },
|
/* 6*/ { BARCODE_MAXICODE, DATA_MODE, -1, "\\0\\E\\a\\b\\t\\n\\v\\f\\r\\e\\G\\R\\x81\\\\", 0, 30, "(144) 04 3E 3E 00 04 07 08 09 0A 0B 03 3D 2C 24 19 1E 23 1B 18 0E 0C 0D 1E 21 3C 1E 3C 31", 0, "" },
|
||||||
/* 7*/ { UNICODE_MODE, -1, "\\u00A01\\u00FF", 0, 12, "EB 21 32 EB 80 D8 49 44 DC 7D 9E 3B", 1, "" },
|
/* 7*/ { BARCODE_PDF417, DATA_MODE, -1, "\\0\\E\\a\\b\\t\\n\\v\\f\\r\\e\\G\\R\\x81\\\\", 0, 120, "(24) 16 901 0 23 655 318 98 18 461 639 893 122 129 92 900 900 872 438 359 646 522 773 831", 0, "" },
|
||||||
/* 8*/ { DATA_MODE, -1, "\\xc3\\xbF", 0, 12, "EB 44 EB 40 81 30 87 17 C5 68 5C 91", 0, "" },
|
/* 8*/ { BARCODE_ULTRA, DATA_MODE, -1, "\\0\\E\\a\\b\\t\\n\\v\\f\\r\\e\\G\\R\\x81\\\\", 0, 20, "(15) 257 0 4 7 8 9 10 11 12 13 27 29 30 129 92", 0, "" },
|
||||||
/* 9*/ { DATA_MODE, -1, "\\u00fF", 0, 12, "EB 44 EB 40 81 30 87 17 C5 68 5C 91", 1, "" },
|
/* 9*/ { BARCODE_DATAMATRIX, DATA_MODE, -1, "\\c", ZINT_ERROR_INVALID_DATA, 0, "Error 234: Unrecognised escape character in input data", 0, "" },
|
||||||
/* 10*/ { UNICODE_MODE, -1, "\\xc3\\xbF", 0, 10, "EB 80 81 47 1E 45 FC 93", 0, "" },
|
/* 10*/ { BARCODE_DATAMATRIX, DATA_MODE, -1, "\\", ZINT_ERROR_INVALID_DATA, 0, "Error 236: Incomplete escape character in input data", 0, "" },
|
||||||
/* 11*/ { UNICODE_MODE, -1, "\\u00fF", 0, 10, "EB 80 81 47 1E 45 FC 93", 1, "" },
|
/* 11*/ { BARCODE_DATAMATRIX, DATA_MODE, -1, "\\x", ZINT_ERROR_INVALID_DATA, 0, "Error 232: Incomplete escape character in input data", 0, "" },
|
||||||
/* 12*/ { DATA_MODE, -1, "\\u", ZINT_ERROR_INVALID_DATA, 0, "Error 209: Incomplete Unicode escape character in input data", 0, "" },
|
/* 12*/ { BARCODE_DATAMATRIX, DATA_MODE, -1, "\\x1", ZINT_ERROR_INVALID_DATA, 0, "Error 232: Incomplete escape character in input data", 0, "" },
|
||||||
/* 13*/ { DATA_MODE, -1, "\\uF", ZINT_ERROR_INVALID_DATA, 0, "Error 209: Incomplete Unicode escape character in input data", 0, "" },
|
/* 13*/ { BARCODE_DATAMATRIX, DATA_MODE, -1, "\\x1g", ZINT_ERROR_INVALID_DATA, 0, "Error 233: Corrupt escape character in input data", 0, "" },
|
||||||
/* 14*/ { DATA_MODE, -1, "\\u0F", ZINT_ERROR_INVALID_DATA, 0, "Error 209: Incomplete Unicode escape character in input data", 0, "" },
|
/* 14*/ { BARCODE_DATAMATRIX, DATA_MODE, -1, "\\xA01\\xFF", 0, 12, "EB 21 32 EB 80 D8 49 44 DC 7D 9E 3B", 0, "" },
|
||||||
/* 15*/ { DATA_MODE, -1, "\\uFG", ZINT_ERROR_INVALID_DATA, 0, "Error 209: Incomplete Unicode escape character in input data", 0, "" },
|
/* 15*/ { BARCODE_DATAMATRIX, UNICODE_MODE, -1, "\\u00A01\\u00FF", 0, 12, "EB 21 32 EB 80 D8 49 44 DC 7D 9E 3B", 1, "" },
|
||||||
/* 16*/ { DATA_MODE, -1, "\\u00F", ZINT_ERROR_INVALID_DATA, 0, "Error 209: Incomplete Unicode escape character in input data", 0, "" },
|
/* 16*/ { BARCODE_DATAMATRIX, DATA_MODE, -1, "\\xc3\\xbF", 0, 12, "EB 44 EB 40 81 30 87 17 C5 68 5C 91", 0, "" },
|
||||||
/* 17*/ { DATA_MODE, -1, "\\u00FG", ZINT_ERROR_INVALID_DATA, 0, "Error 211: Corrupt Unicode escape character in input data", 0, "" },
|
/* 17*/ { BARCODE_DATAMATRIX, DATA_MODE, -1, "\\u00fF", 0, 12, "EB 44 EB 40 81 30 87 17 C5 68 5C 91", 1, "" },
|
||||||
/* 18*/ { DATA_MODE, -1, "\\ufffe", ZINT_ERROR_INVALID_DATA, 0, "Error 246: Invalid Unicode BMP escape character in input data", 0, "Reversed BOM" },
|
/* 18*/ { BARCODE_DATAMATRIX, UNICODE_MODE, -1, "\\xc3\\xbF", 0, 10, "EB 80 81 47 1E 45 FC 93", 0, "" },
|
||||||
/* 19*/ { DATA_MODE, -1, "\\ud800", ZINT_ERROR_INVALID_DATA, 0, "Error 246: Invalid Unicode BMP escape character in input data", 0, "Surrogate" },
|
/* 19*/ { BARCODE_DATAMATRIX, UNICODE_MODE, -1, "\\u00fF", 0, 10, "EB 80 81 47 1E 45 FC 93", 1, "" },
|
||||||
/* 20*/ { DATA_MODE, -1, "\\udfff", ZINT_ERROR_INVALID_DATA, 0, "Error 246: Invalid Unicode BMP escape character in input data", 0, "Surrogate" },
|
/* 20*/ { BARCODE_DATAMATRIX, DATA_MODE, -1, "\\u", ZINT_ERROR_INVALID_DATA, 0, "Error 209: Incomplete Unicode escape character in input data", 0, "" },
|
||||||
/* 21*/ { UNICODE_MODE, 17, "\\xE2\\x82\\xAC", 0, 12, "F1 12 EB 25 81 4A 0A 8C 31 AC E3 2E", 0, "Zint manual 4.10 Ex1" },
|
/* 21*/ { BARCODE_DATAMATRIX, DATA_MODE, -1, "\\uF", ZINT_ERROR_INVALID_DATA, 0, "Error 209: Incomplete Unicode escape character in input data", 0, "" },
|
||||||
/* 22*/ { UNICODE_MODE, 17, "\\u20AC", 0, 12, "F1 12 EB 25 81 4A 0A 8C 31 AC E3 2E", 1, "" },
|
/* 22*/ { BARCODE_DATAMATRIX, DATA_MODE, -1, "\\u0F", ZINT_ERROR_INVALID_DATA, 0, "Error 209: Incomplete Unicode escape character in input data", 0, "" },
|
||||||
/* 23*/ { DATA_MODE, 17, "\\xA4", 0, 12, "F1 12 EB 25 81 4A 0A 8C 31 AC E3 2E", 1, "" },
|
/* 23*/ { BARCODE_DATAMATRIX, DATA_MODE, -1, "\\uFG", ZINT_ERROR_INVALID_DATA, 0, "Error 209: Incomplete Unicode escape character in input data", 0, "" },
|
||||||
/* 24*/ { DATA_MODE, 28, "\\xB1\\x60", 0, 12, "F1 1D EB 32 61 D9 1C 0C C2 46 C3 B2", 0, "Zint manual 4.10 Ex2" },
|
/* 24*/ { BARCODE_DATAMATRIX, DATA_MODE, -1, "\\u00F", ZINT_ERROR_INVALID_DATA, 0, "Error 209: Incomplete Unicode escape character in input data", 0, "" },
|
||||||
/* 25*/ { UNICODE_MODE, 28, "\\u5E38", 0, 12, "F1 1D EB 32 61 D9 1C 0C C2 46 C3 B2", 1, "" },
|
/* 25*/ { BARCODE_DATAMATRIX, DATA_MODE, -1, "\\u00FG", ZINT_ERROR_INVALID_DATA, 0, "Error 211: Corrupt Unicode escape character in input data", 0, "" },
|
||||||
|
/* 26*/ { BARCODE_DATAMATRIX, DATA_MODE, -1, "\\ufffe", ZINT_ERROR_INVALID_DATA, 0, "Error 246: Invalid Unicode BMP escape character in input data", 0, "Reversed BOM" },
|
||||||
|
/* 27*/ { BARCODE_DATAMATRIX, DATA_MODE, -1, "\\ud800", ZINT_ERROR_INVALID_DATA, 0, "Error 246: Invalid Unicode BMP escape character in input data", 0, "Surrogate" },
|
||||||
|
/* 28*/ { BARCODE_DATAMATRIX, DATA_MODE, -1, "\\udfff", ZINT_ERROR_INVALID_DATA, 0, "Error 246: Invalid Unicode BMP escape character in input data", 0, "Surrogate" },
|
||||||
|
/* 29*/ { BARCODE_DATAMATRIX, UNICODE_MODE, 17, "\\xE2\\x82\\xAC", 0, 12, "F1 12 EB 25 81 4A 0A 8C 31 AC E3 2E", 0, "Zint manual 4.10 Ex1" },
|
||||||
|
/* 30*/ { BARCODE_DATAMATRIX, UNICODE_MODE, 17, "\\u20AC", 0, 12, "F1 12 EB 25 81 4A 0A 8C 31 AC E3 2E", 1, "" },
|
||||||
|
/* 31*/ { BARCODE_DATAMATRIX, DATA_MODE, 17, "\\xA4", 0, 12, "F1 12 EB 25 81 4A 0A 8C 31 AC E3 2E", 1, "" },
|
||||||
|
/* 32*/ { BARCODE_DATAMATRIX, DATA_MODE, 28, "\\xB1\\x60", 0, 12, "F1 1D EB 32 61 D9 1C 0C C2 46 C3 B2", 0, "Zint manual 4.10 Ex2" },
|
||||||
|
/* 33*/ { BARCODE_DATAMATRIX, UNICODE_MODE, 28, "\\u5E38", 0, 12, "F1 1D EB 32 61 D9 1C 0C C2 46 C3 B2", 1, "" },
|
||||||
};
|
};
|
||||||
int data_size = ARRAY_SIZE(data);
|
int data_size = ARRAY_SIZE(data);
|
||||||
int i, length, ret;
|
int i, length, ret;
|
||||||
@ -241,14 +250,15 @@ static void test_escape_char_process(int index, int generate, int debug) {
|
|||||||
|
|
||||||
symbol->debug = ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt
|
symbol->debug = ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt
|
||||||
|
|
||||||
length = testUtilSetSymbol(symbol, BARCODE_DATAMATRIX, data[i].input_mode | ESCAPE_MODE, data[i].eci, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug);
|
length = testUtilSetSymbol(symbol, data[i].symbology, data[i].input_mode | ESCAPE_MODE, data[i].eci, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug);
|
||||||
|
|
||||||
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
|
ret = ZBarcode_Encode(symbol, (unsigned char *) data[i].data, length);
|
||||||
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
|
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode ret %d != %d (%s)\n", i, ret, data[i].ret, symbol->errtxt);
|
||||||
|
|
||||||
if (generate) {
|
if (generate) {
|
||||||
printf(" /*%3d*/ { %s, %d, \"%s\", %s, %d, \"%s\", %d, \"%s\" },\n",
|
printf(" /*%3d*/ { %s, %s, %d, \"%s\", %s, %d, \"%s\", %d, \"%s\" },\n",
|
||||||
i, testUtilInputModeName(data[i].input_mode), data[i].eci, testUtilEscape(data[i].data, length, escaped, sizeof(escaped)),
|
i, testUtilBarcodeName(data[i].symbology), testUtilInputModeName(data[i].input_mode), data[i].eci,
|
||||||
|
testUtilEscape(data[i].data, length, escaped, sizeof(escaped)),
|
||||||
testUtilErrorName(data[i].ret), symbol->width, symbol->errtxt, data[i].compare_previous, data[i].comment);
|
testUtilErrorName(data[i].ret), symbol->width, symbol->errtxt, data[i].compare_previous, data[i].comment);
|
||||||
} else {
|
} else {
|
||||||
assert_zero(strcmp(symbol->errtxt, data[i].expected), "i:%d strcmp(%s, %s) != 0\n", i, symbol->errtxt, data[i].expected);
|
assert_zero(strcmp(symbol->errtxt, data[i].expected), "i:%d strcmp(%s, %s) != 0\n", i, symbol->errtxt, data[i].expected);
|
||||||
@ -277,7 +287,7 @@ static void test_escape_char_process(int index, int generate, int debug) {
|
|||||||
|
|
||||||
symbol2->debug = ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt
|
symbol2->debug = ZINT_DEBUG_TEST; // Needed to get codeword dump in errtxt
|
||||||
|
|
||||||
(void) testUtilSetSymbol(symbol2, BARCODE_DATAMATRIX, data[i].input_mode | ESCAPE_MODE, data[i].eci, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug);
|
(void) testUtilSetSymbol(symbol2, data[i].symbology, data[i].input_mode | ESCAPE_MODE, data[i].eci, -1 /*option_1*/, -1, -1, -1 /*output_options*/, data[i].data, -1, debug);
|
||||||
|
|
||||||
ret = ZBarcode_Encode_File(symbol2, input_filename);
|
ret = ZBarcode_Encode_File(symbol2, input_filename);
|
||||||
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode_File ret %d != %d (%s)\n", i, ret, data[i].ret, symbol2->errtxt);
|
assert_equal(ret, data[i].ret, "i:%d ZBarcode_Encode_File ret %d != %d (%s)\n", i, ret, data[i].ret, symbol2->errtxt);
|
||||||
@ -641,6 +651,37 @@ static void test_strip_bom(void) {
|
|||||||
testFinish();
|
testFinish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_zero_outfile(void) {
|
||||||
|
|
||||||
|
int ret;
|
||||||
|
struct zint_symbol *symbol;
|
||||||
|
char *data = "1234";
|
||||||
|
|
||||||
|
testStart("test_zero_outfile");
|
||||||
|
|
||||||
|
symbol = ZBarcode_Create();
|
||||||
|
assert_nonnull(symbol, "Symbol not created\n");
|
||||||
|
|
||||||
|
assert_nonzero(symbol->outfile[0], "ZBarcode_Create() outfile zero\n");
|
||||||
|
symbol->outfile[0] = '\0';
|
||||||
|
|
||||||
|
ret = ZBarcode_Encode(symbol, (unsigned char *) data, 0);
|
||||||
|
assert_zero(ret, "ZBarcode_Encode(%s) ret %d != 0 (%s)\n", data, ret, symbol->errtxt);
|
||||||
|
assert_zero(symbol->outfile[0], "ZBarcode_Encode() outfile non-zero\n");
|
||||||
|
|
||||||
|
ret = ZBarcode_Print(symbol, 0);
|
||||||
|
assert_equal(ret, ZINT_ERROR_INVALID_OPTION, "ZBarcode_Print() ret %d != ZINT_ERROR_INVALID_OPTION (%s)\n", ret, symbol->errtxt);
|
||||||
|
assert_zero(symbol->outfile[0], "ZBarcode_Print() outfile non-zero\n");
|
||||||
|
|
||||||
|
ret = ZBarcode_Buffer(symbol, 0);
|
||||||
|
assert_zero(ret, "ZBarcode_Buffer() ret %d != 0 (%s)\n", ret, symbol->errtxt);
|
||||||
|
assert_zero(symbol->outfile[0], "ZBarcode_Buffer() outfile non-zero\n");
|
||||||
|
|
||||||
|
ZBarcode_Delete(symbol);
|
||||||
|
|
||||||
|
testFinish();
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */
|
testFunction funcs[] = { /* name, func, has_index, has_generate, has_debug */
|
||||||
@ -656,6 +697,7 @@ int main(int argc, char *argv[]) {
|
|||||||
{ "test_valid_id", test_valid_id, 0, 0, 0 },
|
{ "test_valid_id", test_valid_id, 0, 0, 0 },
|
||||||
{ "test_error_tag", test_error_tag, 1, 0, 0 },
|
{ "test_error_tag", test_error_tag, 1, 0, 0 },
|
||||||
{ "test_strip_bom", test_strip_bom, 0, 0, 0 },
|
{ "test_strip_bom", test_strip_bom, 0, 0, 0 },
|
||||||
|
{ "test_zero_outfile", test_zero_outfile, 0, 0, 0 },
|
||||||
};
|
};
|
||||||
|
|
||||||
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));
|
testRun(argc, argv, funcs, ARRAY_SIZE(funcs));
|
||||||
|
@ -558,6 +558,7 @@ const char *testUtilInputModeName(int input_mode) {
|
|||||||
strcpy(buf, "GS1_MODE");
|
strcpy(buf, "GS1_MODE");
|
||||||
set = GS1_MODE;
|
set = GS1_MODE;
|
||||||
} else {
|
} else {
|
||||||
|
strcpy(buf, "DATA_MODE");
|
||||||
set = DATA_MODE;
|
set = DATA_MODE;
|
||||||
}
|
}
|
||||||
for (i = 0; i < data_size; i++) {
|
for (i = 0; i < data_size; i++) {
|
||||||
|
@ -352,11 +352,7 @@ static void test_dump_args(int index, int debug) {
|
|||||||
|
|
||||||
static void test_input(int index, int debug) {
|
static void test_input(int index, int debug) {
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
#define TEST_INPUT_LONG "test_678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234"
|
|
||||||
#else
|
|
||||||
#define TEST_INPUT_LONG "test_67890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
|
#define TEST_INPUT_LONG "test_67890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
|
||||||
#endif
|
|
||||||
|
|
||||||
struct item {
|
struct item {
|
||||||
int b;
|
int b;
|
||||||
@ -405,6 +401,12 @@ static void test_input(int index, int debug) {
|
|||||||
|
|
||||||
if (index != -1 && i != index) continue;
|
if (index != -1 && i != index) continue;
|
||||||
if ((debug & ZINT_DEBUG_TEST_PRINT) && !(debug & ZINT_DEBUG_TEST_LESS_NOISY)) printf("i:%d\n", i);
|
if ((debug & ZINT_DEBUG_TEST_PRINT) && !(debug & ZINT_DEBUG_TEST_LESS_NOISY)) printf("i:%d\n", i);
|
||||||
|
#ifdef _WIN32
|
||||||
|
if (data[i].outfile && (int) strlen(data[i].outfile) > 50) {
|
||||||
|
if (debug & ZINT_DEBUG_TEST_PRINT) printf("%d not Windows compatible (outfile length %d > 50)\n", i, (int) strlen(data[i].outfile));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
strcpy(cmd, "zint");
|
strcpy(cmd, "zint");
|
||||||
if (debug & ZINT_DEBUG_PRINT) {
|
if (debug & ZINT_DEBUG_PRINT) {
|
||||||
|
Loading…
Reference in New Issue
Block a user