mirror of
https://git.code.sf.net/p/zint/code
synced 2026-05-09 15:43:47 +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:
@@ -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));
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* filemem.c - write to file/memory abstraction */
|
||||
/*
|
||||
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
|
||||
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);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* filemem.h - write to file/memory abstraction */
|
||||
/*
|
||||
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
|
||||
modification, are permitted provided that the following conditions
|
||||
@@ -40,11 +40,6 @@ extern "C" {
|
||||
#include <stdio.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 {
|
||||
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
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user