mirror of
https://git.code.sf.net/p/zint/code
synced 2026-01-23 03:45:58 +00:00
ZBarcode_Encode_Segs: fuller debug output (all input fields)
test suite: fuzz: update for new symbologies & suppress some clang-tidy warnings common: better `z_iscntrl()` BWIPP: update to latest
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
/* common.h - Header for all common functions in common.c */
|
||||
/*
|
||||
libzint - the open source barcode library
|
||||
Copyright (C) 2009-2025 Robin Stuart <rstuart114@gmail.com>
|
||||
Copyright (C) 2009-2026 Robin Stuart <rstuart114@gmail.com>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
@@ -141,7 +141,7 @@ typedef unsigned __int64 uint64_t;
|
||||
#define z_isupper(c) ((c) >= 'A' && (c) <= 'Z')
|
||||
#define z_islower(c) ((c) >= 'a' && (c) <= 'z')
|
||||
#define z_isascii(c) (!((c) & ~0x7F))
|
||||
#define z_iscntrl(c) (z_isascii(c) && ((c) < 32 || (c) == 127))
|
||||
#define z_iscntrl(c) (!((c) & ~0x1F) || (c) == 127)
|
||||
|
||||
/* Shorthands to cast away char pointer signedness */
|
||||
#define ZUCP(p) ((unsigned char *) (p))
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* library.c - external functions of libzint */
|
||||
/*
|
||||
libzint - the open source barcode library
|
||||
Copyright (C) 2009-2025 Robin Stuart <rstuart114@gmail.com>
|
||||
Copyright (C) 2009-2026 Robin Stuart <rstuart114@gmail.com>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
@@ -1048,18 +1048,28 @@ int ZBarcode_Encode_Segs(struct zint_symbol *symbol, const struct zint_seg segs[
|
||||
const int len = local_segs[0].length;
|
||||
const int primary_len = symbol->primary[0] ? (int) strlen(symbol->primary) : 0;
|
||||
char name[32];
|
||||
char source[151], primary[151]; /* 30*5 + 1 = 151 */
|
||||
char source[1001]; /* 200*5 + 1 = 1001 */
|
||||
(void) ZBarcode_BarcodeName(symbol->symbology, name);
|
||||
z_debug_print_escape(local_segs[0].source, len > 30 ? 30 : len, source);
|
||||
z_debug_print_escape(ZCUCP(symbol->primary), primary_len > 30 ? 30 : primary_len, primary);
|
||||
printf("\nZBarcode_Encode_Segs: %s (%d), input_mode: 0x%X, ECI: %d, option_1/2/3: (%d, %d, %d)\n"
|
||||
" scale: %g, output_options: 0x%X, fg: %s, bg: %s, seg_count: %d,\n"
|
||||
" %ssource%s (%d): \"%s\",\n"
|
||||
" %sprimary (%d): \"%s\"\n",
|
||||
name, 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,
|
||||
seg_count, len > 30 ? "first 30 " : "", seg_count > 1 ? "[0]" : "", len, source,
|
||||
primary_len > 30 ? "first 30 " : "", primary_len, primary);
|
||||
z_debug_print_escape(local_segs[0].source, len > 200 ? 200 : len, source);
|
||||
printf("\nZBarcode_Encode_Segs: %s (%d), height %g, scale: %g, whitespace: (%d, %d), border_width: %d\n"
|
||||
" output_options: 0x%X, fg: \"%s\", bg: \"%s\"\n"
|
||||
" outfile: \"%s\"\n"
|
||||
" primary (%d): \"%s\"\n"
|
||||
" option_1/2/3: (%d, %d, %d), show_hrt: %d, input_mode: 0x%X, ECI: %d, dpmm: %g"
|
||||
", dot_size: %g\n"
|
||||
" text_gap: %g, guard_descent: %g, structapp index/count/id: (%d, %d, \"%s\")"
|
||||
", warn_level: %d, seg_count %d\n"
|
||||
" %ssource%s (%d): \"%s\"\n",
|
||||
name, symbol->symbology, symbol->height, symbol->scale, symbol->whitespace_width,
|
||||
symbol->whitespace_height, symbol->border_width,
|
||||
symbol->output_options, symbol->fgcolour, symbol->bgcolour,
|
||||
symbol->outfile,
|
||||
primary_len, symbol->primary,
|
||||
symbol->option_1, symbol->option_2, symbol->option_3, symbol->show_hrt, symbol->input_mode,
|
||||
symbol->eci, symbol->dpmm, symbol->dot_size,
|
||||
symbol->text_gap, symbol->guard_descent, symbol->structapp.index, symbol->structapp.count,
|
||||
symbol->structapp.id, symbol->warn_level, seg_count,
|
||||
len > 200 ? "first 200 " : "", seg_count > 1 ? "[0]" : "", len, source);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* fuzz.h - common functions for fuzzing libzint */
|
||||
/*
|
||||
libzint - the open source barcode library
|
||||
Copyright (C) 2024-2025 Robin Stuart <rstuart114@gmail.com>
|
||||
Copyright (C) 2024-2026 Robin Stuart <rstuart114@gmail.com>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
@@ -175,12 +175,12 @@ static const struct settings_item settings[] = {
|
||||
{ 7, BARCODE_C25IND, NEON_F, 0, -1, 0, 2, 0, 1, 79 },
|
||||
{ 8, BARCODE_CODE39, SILVER_F, 0, -1, 0, 2, 0, 1, 86 },
|
||||
{ 9, BARCODE_EXCODE39, SILVER_F, 0, -1, 0, 2, 0, 1, 86 },
|
||||
{ 10, /*symbology*/ -1, /*sane_flag*/ 0, /*opt_1*/ 0, -1, /*opt_2*/ 0, -1, /*opt_3*/ 0, /*len*/ 0, -1 },
|
||||
{ 11, /*symbology*/ -1, /*sane_flag*/ 0, /*opt_1*/ 0, -1, /*opt_2*/ 0, -1, /*opt_3*/ 0, /*len*/ 0, -1 },
|
||||
{ 12, /*symbology*/ -1, /*sane_flag*/ 0, /*opt_1*/ 0, -1, /*opt_2*/ 0, -1, /*opt_3*/ 0, /*len*/ 0, -1 },
|
||||
{ 10, BARCODE_EAN8, SODIUM_PLS_F, 0, -1, 0, -1, 0, 1, 14 },
|
||||
{ 11, BARCODE_EAN_2ADDON, NEON_F, 0, -1, 0, -1, 0, 1, 2 },
|
||||
{ 12, BARCODE_EAN_5ADDON, NEON_F, 0, -1, 0, -1, 0, 1, 5 },
|
||||
{ 13, BARCODE_EANX, SODIUM_PLS_F, 0, -1, 0, -1, 0, 1, 19 },
|
||||
{ 14, BARCODE_EANX_CHK, SODIUM_PLS_F, 0, -1, 0, -1, 0, 1, 19 },
|
||||
{ 15, /*symbology*/ -1, /*sane_flag*/ 0, /*opt_1*/ 0, -1, /*opt_2*/ 0, -1, /*opt_3*/ 0, /*len*/ 0, -1 },
|
||||
{ 15, BARCODE_EAN13, SODIUM_PLS_F, 0, -1, 0, -1, 0, 1, 19 },
|
||||
{ 16, BARCODE_GS1_128, ASCII_PRT_F, 0, -1, 0, -1, 0, 3, 198 },
|
||||
{ 17, /*symbology*/ -1, /*sane_flag*/ 0, /*opt_1*/ 0, -1, /*opt_2*/ 0, -1, /*opt_3*/ 0, /*len*/ 0, -1 },
|
||||
{ 18, BARCODE_CODABAR, CALCIUM_F, 0, -1, 0, 2, 0, 3, 103 },
|
||||
@@ -313,6 +313,8 @@ static const struct settings_item settings[] = {
|
||||
{ 145, BARCODE_RMQR, 0, -1, 4, 0, 38, 0, 1, 361 },
|
||||
{ 146, BARCODE_BC412, ARSENIC_F, 0, -1, 0, -1, 0, 7, 18 },
|
||||
{ 147, BARCODE_DXFILMEDGE, SILVER_F, 0, -1, 0, -1, 0, 1, 10 },
|
||||
{ 148, BARCODE_EAN8_CC, SODIUM_PLS_F, 0, 2, 0, -1, 0, 1, 335 },
|
||||
{ 149, BARCODE_EAN13_CC, SODIUM_PLS_F, 0, 2, 0, -1, 0, 1, 338 },
|
||||
};
|
||||
|
||||
/* Make sure value `v` is between `min` and `max` */
|
||||
|
||||
Binary file not shown.
@@ -1,7 +1,7 @@
|
||||
/* fuzz_gs1.c - fuzzer for libzint (GS1-enabled symbologies, GS1_MODE) */
|
||||
/*
|
||||
libzint - the open source barcode library
|
||||
Copyright (C) 2024 Robin Stuart <rstuart114@gmail.com>
|
||||
Copyright (C) 2024-2026 Robin Stuart <rstuart114@gmail.com>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
@@ -84,11 +84,11 @@ int LLVMFuzzerTestOneInput(const unsigned char *data, size_t size) {
|
||||
|
||||
if (is_composite) {
|
||||
if (idx == BARCODE_GS1_128_CC || idx == BARCODE_DBAR_EXP_CC || idx == BARCODE_DBAR_EXPSTK_CC) {
|
||||
strcpy(symbol->primary, primary_ai);
|
||||
memcpy(symbol->primary, primary_ai, sizeof(primary_ai));
|
||||
} else if (idx == BARCODE_UPCE_CC) {
|
||||
strcpy(symbol->primary, primary_upce);
|
||||
memcpy(symbol->primary, primary_upce, sizeof(primary_upce));
|
||||
} else {
|
||||
strcpy(symbol->primary, primary);
|
||||
memcpy(symbol->primary, primary, sizeof(primary));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Binary file not shown.
@@ -1,5 +1,6 @@
|
||||
/* gen_corpora.c - write out initial fuzz data for zint, allowing for how `set_symbol()` in "fuzz.h" uses first X
|
||||
bytes to set various `zint_symbol` members (namely `input_mode`, `option_1`, `option_2`, `eci`, `option_3`) */
|
||||
/* NOLINTBEGIN(clang-diagnostic-comment) */
|
||||
/*
|
||||
From "backend/tests/fuzz" directory:
|
||||
|
||||
@@ -10,6 +11,7 @@
|
||||
zip -j fuzz_data_seed_corpus.zip fuzz_data_corpus/*
|
||||
zip -j fuzz_gs1_seed_corpus.zip fuzz_gs1_corpus/*
|
||||
*/
|
||||
/* NOLINTEND(clang-diagnostic-comment) */
|
||||
/*
|
||||
libzint - the open source barcode library
|
||||
Copyright (C) 2024-2025 Robin Stuart <rstuart114@gmail.com>
|
||||
@@ -52,6 +54,7 @@ extern "C" {
|
||||
#include "fuzz.h"
|
||||
|
||||
/* Data item */
|
||||
/* NOLINTNEXTLINE(clang-analyzer-optin.performance.Padding) disable "Excessive padding" warning */
|
||||
struct item {
|
||||
int test_fuzz_idx;
|
||||
int symbology;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
libzint - the open source barcode library
|
||||
Copyright (C) 2019-2025 Robin Stuart <rstuart114@gmail.com>
|
||||
Copyright (C) 2019-2026 Robin Stuart <rstuart114@gmail.com>
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
@@ -51,6 +51,44 @@ static int is_sane_orig(const char test_string[], const unsigned char source[],
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void test_isXXX(const testCtx *const p_ctx) {
|
||||
|
||||
struct item {
|
||||
char ch;
|
||||
int ret_isascii;
|
||||
int ret_iscntrl;
|
||||
};
|
||||
/* s/\/\*[ 0-9]*\*\//\=printf("\/\*%3d*\/", line(".") - line("'<")): */
|
||||
static const struct item data[] = {
|
||||
/* 0*/ { '\177', 1, 1 }, /* DEL */
|
||||
/* 1*/ { '\200', 0, 0 },
|
||||
/* 3*/ { '\0', 1, 1 },
|
||||
/* 3*/ { '\001', 1, 1 }, /* SOH */
|
||||
/* 2*/ { '\t', 1, 1 },
|
||||
/* 4*/ { '\037', 1, 1 }, /* US */
|
||||
/* 5*/ { ' ', 1, 0 },
|
||||
/* 6*/ { '!', 1, 0 },
|
||||
/* 7*/ { '~', 1, 0 },
|
||||
};
|
||||
const int data_size = ARRAY_SIZE(data);
|
||||
int i, ret;
|
||||
|
||||
testStart(p_ctx->func_name);
|
||||
|
||||
for (i = 0; i < data_size; i++) {
|
||||
|
||||
if (testContinue(p_ctx, i)) continue;
|
||||
|
||||
ret = z_isascii(data[i].ch);
|
||||
assert_equal(ret, data[i].ret_isascii, "i:%d isascii ret %d != %d\n", i, ret, data[i].ret_isascii);
|
||||
|
||||
ret = z_iscntrl(data[i].ch);
|
||||
assert_equal(ret, data[i].ret_iscntrl, "i:%d iscntrl ret %d != %d\n", i, ret, data[i].ret_iscntrl);
|
||||
}
|
||||
|
||||
testFinish();
|
||||
}
|
||||
|
||||
static void test_to_int(const testCtx *const p_ctx) {
|
||||
|
||||
struct item {
|
||||
@@ -1439,6 +1477,7 @@ static void test_debug_test_codeword_dump_int(const testCtx *const p_ctx) {
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
testFunction funcs[] = { /* name, func */
|
||||
{ "test_isXXX", test_isXXX },
|
||||
{ "test_to_int", test_to_int },
|
||||
{ "test_to_upper", test_to_upper },
|
||||
{ "test_chr_cnt", test_chr_cnt },
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user