filemem: fix fwrite() return check in fm_write();

test `ferror()` also in `fm_err()` if `err` zero and file
NetBSD: add instructions and some workarounds (`getopt_long_only()`
  in particular)
qzint: check `__GNUC__` version for "-Wstringop-truncation"
  suppression
This commit is contained in:
gitlost 2023-12-29 19:34:44 +00:00
parent 98f86727cc
commit 3950b49050
12 changed files with 64 additions and 29 deletions

View file

@ -187,7 +187,7 @@ INTERNAL int fm_write(const void *restrict ptr, const size_t size, const size_t
fm_setpos(fmp, fmp->mempos + tot_size);
return 1;
}
if (fwrite(ptr, size, nitems, fmp->fp) == 0) {
if (fwrite(ptr, size, nitems, fmp->fp) != nitems) {
return fm_seterr(fmp, errno);
}
return 1;
@ -304,11 +304,8 @@ INTERNAL int fm_printf(struct filemem *restrict const fmp, const char *fmt, ...)
}
va_start(ap, fmt);
ret = vfprintf(fmp->fp, fmt, ap) >= 0; /* NOLINT(clang-analyzer-valist.Uninitialized) - see above */
if (!ret) {
(void) fm_seterr(fmp, errno);
}
va_end(ap);
return ret != 0;
return ret ? 1 : fm_seterr(fmp, errno);
}
/* Output float without trailing zeroes to `fmp` with decimal pts `dp` (precision), returning 1 on success, 0 on
@ -436,9 +433,12 @@ INTERNAL long fm_tell(struct filemem *restrict const fmp) {
return ret;
}
/* Return `err`, which uses `errno` values */
/* Return `err`, which uses `errno` values; if file and `err` not set, test `ferror()` also */
INTERNAL int fm_error(struct filemem *restrict const fmp) {
assert(fmp);
if (fmp->err == 0 && !(fmp->flags & BARCODE_MEMORY_FILE) && ferror(fmp->fp)) {
(void) fm_seterr(fmp, EIO);
}
return fmp->err;
}

View file

@ -84,7 +84,7 @@ INTERNAL int fm_seek(struct filemem *restrict const fmp, const long offset, cons
/* `ftell()` returns current file/memory offset if successful, -1 on failure */
INTERNAL long fm_tell(struct filemem *restrict const fmp);
/* Return `err`, which uses `errno` values */
/* Return `err`, which uses `errno` values; if file and `err` not set, test `ferror()` also */
INTERNAL int fm_error(struct filemem *restrict const fmp);
/* `fflush()` if file, no-op if memory, returning 1 on success, 0 on failure

View file

@ -263,17 +263,18 @@ INTERNAL int ps_plot(struct zint_symbol *symbol) {
}
/* Start writing the header */
fm_puts("%!PS-Adobe-3.0 EPSF-3.0\n", fmp);
fm_puts("%!PS-Adobe-3.0 EPSF-3.0\n"
"%%Creator: Zint ", fmp);
if (ZINT_VERSION_BUILD) {
fm_printf(fmp, "%%%%Creator: Zint %d.%d.%d.%d\n",
fm_printf(fmp, "%d.%d.%d.%d\n",
ZINT_VERSION_MAJOR, ZINT_VERSION_MINOR, ZINT_VERSION_RELEASE, ZINT_VERSION_BUILD);
} else {
fm_printf(fmp, "%%%%Creator: Zint %d.%d.%d\n", ZINT_VERSION_MAJOR, ZINT_VERSION_MINOR, ZINT_VERSION_RELEASE);
fm_printf(fmp, "%d.%d.%d\n", ZINT_VERSION_MAJOR, ZINT_VERSION_MINOR, ZINT_VERSION_RELEASE);
}
fm_puts("%%Title: Zint Generated Symbol\n"
"%%Pages: 0\n", fmp);
fm_printf(fmp, "%%%%BoundingBox: 0 0 %d %d\n",
(int) ceilf(symbol->vector->width), (int) ceilf(symbol->vector->height));
"%%Pages: 0\n"
"%%BoundingBox: 0 0 ", fmp);
fm_printf(fmp, "%d %d\n", (int) ceilf(symbol->vector->width), (int) ceilf(symbol->vector->height));
fm_puts("%%EndComments\n", fmp);
/* Definitions */

View file

@ -34,7 +34,6 @@
#include <math.h>
#include <sys/stat.h>
#include "testcommon.h"
#include "../common.h"
static void test_checks(const testCtx *const p_ctx) {
int debug = p_ctx->debug;
@ -946,14 +945,20 @@ static void test_encode_file_unreadable(const testCtx *const p_ctx) {
/* #181 Nico Gunkel OSS-Fuzz (buffer not freed on fread() error) Note: unable to reproduce fread() error using this method */
static void test_encode_file_directory(const testCtx *const p_ctx) {
#ifndef __NetBSD__
int ret;
struct zint_symbol *symbol;
char dirname[] = "in_dir";
#endif
(void)p_ctx;
testStart("test_encode_file_directory");
#ifdef __NetBSD__
/* Reading a directory works on NetBSD, and get `code128()` ZINT_ERROR_TOO_LONG instead */
testSkip("Test not implemented on NetBSD");
#else
symbol = ZBarcode_Create();
assert_nonnull(symbol, "Symbol not created\n");
@ -970,6 +975,7 @@ static void test_encode_file_directory(const testCtx *const p_ctx) {
ZBarcode_Delete(symbol);
testFinish();
#endif /* __NetBSD__ */
}
static void test_encode_file(const testCtx *const p_ctx) {

View file

@ -123,7 +123,7 @@ static void test_colour_get_rgb(const testCtx *const p_ctx) {
unsigned char red = 0, green = 0, blue = 0, alpha = 0, rgb_alpha = 0;
int cyan, magenta, yellow, black;
int have_alpha;
char rgb[9];
char rgb[16];
char cmyk[16];
if (testContinue(p_ctx, i)) continue;
@ -181,7 +181,7 @@ static void test_colour_get_cmyk(const testCtx *const p_ctx) {
for (i = 0; i < data_size; i++) {
int cyan, magenta, yellow, black;
unsigned char red, green, blue, alpha, rgb_alpha;
char rgb[9];
char rgb[16];
if (testContinue(p_ctx, i)) continue;