diff --git a/backend/aztec.c b/backend/aztec.c index 278fb025..32ae8c6f 100644 --- a/backend/aztec.c +++ b/backend/aztec.c @@ -980,7 +980,8 @@ static int az_binary_string(const unsigned char source[], const int length, int const int entry_bp = bp; #endif - if (!az_state_list_init(list, length)) { + assert(length < USHRT_MAX); + if (!az_state_list_init(list, (unsigned short) length)) { return 0; } memset(list->states, 0, sizeof(struct az_state)); diff --git a/backend/common.c b/backend/common.c index a4db539d..0b9b6740 100644 --- a/backend/common.c +++ b/backend/common.c @@ -960,7 +960,7 @@ INTERNAL void z_hrt_printf_nochk(struct zint_symbol *symbol, const char *fmt, .. va_start(ap, fmt); -#ifdef ZINT_IS_C89 +#ifdef Z_NO_VSNPRINTF size = vsprintf((char *) symbol->text, fmt, ap); #else size = vsnprintf((char *) symbol->text, sizeof(symbol->text), fmt, ap); diff --git a/backend/common.h b/backend/common.h index 2573a5e6..d2da2e21 100644 --- a/backend/common.h +++ b/backend/common.h @@ -133,6 +133,11 @@ typedef unsigned __int64 uint64_t; # define roundf(arg) floorf((arg) + 0.5f) #endif +/* Whether `vsnprintf()` available */ +#if (defined(_MSC_VER) && _MSC_VER < 1900) || defined(ZINT_IS_C89) /* Pre-MSVC 2015 (C++ 14.0) or C89 */ +#define Z_NO_VSNPRINTF +#endif + /* Is float integral value? (https://stackoverflow.com/a/40404149) */ #define z_isfintf(arg) (fmodf(arg, 1.0f) == 0.0f) diff --git a/backend/filemem.c b/backend/filemem.c index 65bfbc7a..37fafa6f 100644 --- a/backend/filemem.c +++ b/backend/filemem.c @@ -1,7 +1,7 @@ /* filemem.c - write to file/memory abstraction */ /* libzint - the open source barcode library - Copyright (C) 2023-2025 Robin Stuart + Copyright (C) 2023-2026 Robin Stuart Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions @@ -84,7 +84,7 @@ static void fm_clear_mem(struct filemem *restrict const fmp) { fmp->mem = NULL; } fmp->memsize = fmp->mempos = fmp->memend = 0; -#ifdef FM_NO_VSNPRINTF +#ifdef Z_NO_VSNPRINTF if (fmp->fp_null) { (void) fclose(fmp->fp_null); fmp->fp_null = NULL; @@ -100,7 +100,7 @@ INTERNAL int zint_fm_open(struct filemem *restrict const fmp, struct zint_symbol fmp->memsize = fmp->mempos = fmp->memend = 0; fmp->flags = symbol->output_options & (BARCODE_STDOUT | BARCODE_MEMORY_FILE); fmp->err = 0; -#ifdef FM_NO_VSNPRINTF +#ifdef Z_NO_VSNPRINTF fmp->fp_null = NULL; #endif @@ -240,7 +240,7 @@ INTERNAL int zint_fm_puts(const char *str, struct filemem *restrict const fmp) { return 1; } -#ifdef FM_NO_VSNPRINTF +#ifdef Z_NO_VSNPRINTF # ifdef _WIN32 # define DEV_NULL "NUL" # else @@ -254,14 +254,14 @@ static int fm_vprintf(struct filemem *restrict const fmp, const char *fmt, va_li int size, check; /* Adapted from https://stackoverflow.com/a/52558247/664741 */ -#ifdef FM_NO_VSNPRINTF +#ifdef Z_NO_VSNPRINTF if (!fmp->fp_null && !(fmp->fp_null = fopen(DEV_NULL, "wb"))) { return fm_seterr(fmp, errno); } #endif va_copy(cpy, ap); -#ifdef FM_NO_VSNPRINTF +#ifdef Z_NO_VSNPRINTF size = vfprintf(fmp->fp_null, fmt, cpy); #else size = vsnprintf(NULL, 0, fmt, cpy); @@ -276,7 +276,7 @@ static int fm_vprintf(struct filemem *restrict const fmp, const char *fmt, va_li return 0; } -#ifdef FM_NO_VSNPRINTF +#ifdef Z_NO_VSNPRINTF check = vsprintf((char *) fmp->mem + fmp->mempos, fmt, ap); #else check = vsnprintf((char *) fmp->mem + fmp->mempos, size + 1, fmt, ap); diff --git a/backend/filemem.h b/backend/filemem.h index 8509ae36..f096884b 100644 --- a/backend/filemem.h +++ b/backend/filemem.h @@ -1,7 +1,7 @@ /* filemem.h - write to file/memory abstraction */ /* libzint - the open source barcode library - Copyright (C) 2023-2025 Robin Stuart + Copyright (C) 2023-2026 Robin Stuart Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions @@ -40,11 +40,6 @@ extern "C" { #include #include "common.h" -/* Whether `vsnprintf()` available */ -#if (defined(_MSC_VER) && _MSC_VER < 1900) || defined(ZINT_IS_C89) /* Pre-MSVC 2015 (C++ 14.0) or C89 */ -#define FM_NO_VSNPRINTF -#endif - struct filemem { FILE *fp; unsigned char *mem; @@ -53,7 +48,7 @@ struct filemem { size_t memend; /* For use by `zint_fm_seek()`, points to highest `mempos` reached */ int flags; /* BARCODE_MEMORY_FILE or BARCODE_STDOUT */ int err; /* `errno` values, reset only on `zint_fm_open()` */ -#ifdef FM_NO_VSNPRINTF +#ifdef Z_NO_VSNPRINTF FILE *fp_null; /* Only used for BARCODE_MEMORY_FILE */ #endif }; diff --git a/backend/gs1.c b/backend/gs1.c index d77136f0..c8643c09 100644 --- a/backend/gs1.c +++ b/backend/gs1.c @@ -57,7 +57,7 @@ ZINT_FORMAT_PRINTF(2, 3) static int gs1_err_msg_printf_nochk(char err_msg[50], c int size; va_start(ap, fmt); -#ifdef ZINT_IS_C89 +#ifdef Z_NO_VSNPRINTF size = vsprintf(err_msg, fmt, ap); #else size = vsnprintf(err_msg, 50, fmt, ap);