1
0
mirror of https://git.code.sf.net/p/zint/code synced 2026-06-09 23:23:36 +00:00

common: move FM_NO_VSNPRINTF (filemem) -> Z_NO_VSNPRINTF & use

AZTEC: suppress MSVC warning C4761: integral size mismatch in arg
This commit is contained in:
gitlost
2026-05-05 21:34:58 +01:00
parent 88ca9cc43c
commit 0a617a410b
6 changed files with 18 additions and 17 deletions
+2 -1
View File
@@ -980,7 +980,8 @@ static int az_binary_string(const unsigned char source[], const int length, int
const int entry_bp = bp; const int entry_bp = bp;
#endif #endif
if (!az_state_list_init(list, length)) { assert(length < USHRT_MAX);
if (!az_state_list_init(list, (unsigned short) length)) {
return 0; return 0;
} }
memset(list->states, 0, sizeof(struct az_state)); memset(list->states, 0, sizeof(struct az_state));
+1 -1
View File
@@ -960,7 +960,7 @@ INTERNAL void z_hrt_printf_nochk(struct zint_symbol *symbol, const char *fmt, ..
va_start(ap, fmt); va_start(ap, fmt);
#ifdef ZINT_IS_C89 #ifdef Z_NO_VSNPRINTF
size = vsprintf((char *) symbol->text, fmt, ap); size = vsprintf((char *) symbol->text, fmt, ap);
#else #else
size = vsnprintf((char *) symbol->text, sizeof(symbol->text), fmt, ap); size = vsnprintf((char *) symbol->text, sizeof(symbol->text), fmt, ap);
+5
View File
@@ -133,6 +133,11 @@ typedef unsigned __int64 uint64_t;
# define roundf(arg) floorf((arg) + 0.5f) # define roundf(arg) floorf((arg) + 0.5f)
#endif #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) */ /* Is float integral value? (https://stackoverflow.com/a/40404149) */
#define z_isfintf(arg) (fmodf(arg, 1.0f) == 0.0f) #define z_isfintf(arg) (fmodf(arg, 1.0f) == 0.0f)
+7 -7
View File
@@ -1,7 +1,7 @@
/* filemem.c - write to file/memory abstraction */ /* filemem.c - write to file/memory abstraction */
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2023-2025 Robin Stuart <rstuart114@gmail.com> Copyright (C) 2023-2026 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions 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->mem = NULL;
} }
fmp->memsize = fmp->mempos = fmp->memend = 0; fmp->memsize = fmp->mempos = fmp->memend = 0;
#ifdef FM_NO_VSNPRINTF #ifdef Z_NO_VSNPRINTF
if (fmp->fp_null) { if (fmp->fp_null) {
(void) fclose(fmp->fp_null); (void) fclose(fmp->fp_null);
fmp->fp_null = 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->memsize = fmp->mempos = fmp->memend = 0;
fmp->flags = symbol->output_options & (BARCODE_STDOUT | BARCODE_MEMORY_FILE); fmp->flags = symbol->output_options & (BARCODE_STDOUT | BARCODE_MEMORY_FILE);
fmp->err = 0; fmp->err = 0;
#ifdef FM_NO_VSNPRINTF #ifdef Z_NO_VSNPRINTF
fmp->fp_null = NULL; fmp->fp_null = NULL;
#endif #endif
@@ -240,7 +240,7 @@ INTERNAL int zint_fm_puts(const char *str, struct filemem *restrict const fmp) {
return 1; return 1;
} }
#ifdef FM_NO_VSNPRINTF #ifdef Z_NO_VSNPRINTF
# ifdef _WIN32 # ifdef _WIN32
# define DEV_NULL "NUL" # define DEV_NULL "NUL"
# else # else
@@ -254,14 +254,14 @@ static int fm_vprintf(struct filemem *restrict const fmp, const char *fmt, va_li
int size, check; int size, check;
/* Adapted from https://stackoverflow.com/a/52558247/664741 */ /* 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"))) { if (!fmp->fp_null && !(fmp->fp_null = fopen(DEV_NULL, "wb"))) {
return fm_seterr(fmp, errno); return fm_seterr(fmp, errno);
} }
#endif #endif
va_copy(cpy, ap); va_copy(cpy, ap);
#ifdef FM_NO_VSNPRINTF #ifdef Z_NO_VSNPRINTF
size = vfprintf(fmp->fp_null, fmt, cpy); size = vfprintf(fmp->fp_null, fmt, cpy);
#else #else
size = vsnprintf(NULL, 0, fmt, cpy); 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; return 0;
} }
#ifdef FM_NO_VSNPRINTF #ifdef Z_NO_VSNPRINTF
check = vsprintf((char *) fmp->mem + fmp->mempos, fmt, ap); check = vsprintf((char *) fmp->mem + fmp->mempos, fmt, ap);
#else #else
check = vsnprintf((char *) fmp->mem + fmp->mempos, size + 1, fmt, ap); check = vsnprintf((char *) fmp->mem + fmp->mempos, size + 1, fmt, ap);
+2 -7
View File
@@ -1,7 +1,7 @@
/* filemem.h - write to file/memory abstraction */ /* filemem.h - write to file/memory abstraction */
/* /*
libzint - the open source barcode library libzint - the open source barcode library
Copyright (C) 2023-2025 Robin Stuart <rstuart114@gmail.com> Copyright (C) 2023-2026 Robin Stuart <rstuart114@gmail.com>
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
@@ -40,11 +40,6 @@ extern "C" {
#include <stdio.h> #include <stdio.h>
#include "common.h" #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 { struct filemem {
FILE *fp; FILE *fp;
unsigned char *mem; unsigned char *mem;
@@ -53,7 +48,7 @@ struct filemem {
size_t memend; /* For use by `zint_fm_seek()`, points to highest `mempos` reached */ size_t memend; /* For use by `zint_fm_seek()`, points to highest `mempos` reached */
int flags; /* BARCODE_MEMORY_FILE or BARCODE_STDOUT */ int flags; /* BARCODE_MEMORY_FILE or BARCODE_STDOUT */
int err; /* `errno` values, reset only on `zint_fm_open()` */ 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 */ FILE *fp_null; /* Only used for BARCODE_MEMORY_FILE */
#endif #endif
}; };
+1 -1
View File
@@ -57,7 +57,7 @@ ZINT_FORMAT_PRINTF(2, 3) static int gs1_err_msg_printf_nochk(char err_msg[50], c
int size; int size;
va_start(ap, fmt); va_start(ap, fmt);
#ifdef ZINT_IS_C89 #ifdef Z_NO_VSNPRINTF
size = vsprintf(err_msg, fmt, ap); size = vsprintf(err_msg, fmt, ap);
#else #else
size = vsnprintf(err_msg, 50, fmt, ap); size = vsnprintf(err_msg, 50, fmt, ap);