From 1449866d1861f9e8e1fd9486105d070e5d06201a Mon Sep 17 00:00:00 2001 From: gitlost Date: Wed, 17 Jan 2024 21:55:11 +0000 Subject: [PATCH] CMake: check for `getopt_long_only()` instead of just `getopt()` so behaviour of CLI same general: AIX compat, suppress some warnings --- CMakeLists.txt | 6 +++--- backend/common.c | 6 +++--- backend/common.h | 4 ++-- backend/output.h | 4 ++-- backend/tests/test_large.c | 6 ++++-- backend/tests/test_library.c | 9 ++++----- backend/tests/testcommon.c | 9 +++++---- frontend/main.c | 19 ++++++++++--------- frontend/tests/test_args.c | 5 +---- 9 files changed, 34 insertions(+), 34 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5daebe64..d4b76ac8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ # Copyright (C) 2008 by BogDan Vatra < bogdan@licentia.eu > -# Copyright (C) 2009-2023 Robin Stuart +# Copyright (C) 2009-2024 Robin Stuart # vim: set ts=4 sw=4 et : cmake_minimum_required(VERSION 3.5) @@ -139,8 +139,8 @@ if(APPLE) endif() endif() -check_function_exists(getopt HAVE_GETOPT) -if(NOT HAVE_GETOPT) +check_function_exists(getopt_long_only HAVE_GETOPT_LONG_ONLY) +if(NOT HAVE_GETOPT_LONG_ONLY) add_subdirectory(getopt) endif() diff --git a/backend/common.c b/backend/common.c index 4bf6b981..66bdbdfe 100644 --- a/backend/common.c +++ b/backend/common.c @@ -1,7 +1,7 @@ /* common.c - Contains functions needed for a number of barcodes */ /* libzint - the open source barcode library - Copyright (C) 2008-2023 Robin Stuart + Copyright (C) 2008-2024 Robin Stuart Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions @@ -607,7 +607,7 @@ INTERNAL char *debug_print_escape(const unsigned char *source, const int first_l #ifdef ZINT_TEST /* Suppress gcc warning null destination pointer [-Wformat-overflow=] false-positive */ -#if defined(__GNUC__) && !defined(__clang__) +#if defined(__GNUC__) && !defined(__clang__) && __GNUC__ >= 7 #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wformat-overflow=" #endif @@ -660,7 +660,7 @@ INTERNAL void debug_test_codeword_dump_int(struct zint_symbol *symbol, const int } symbol->errtxt[strlen(symbol->errtxt) - 1] = '\0'; /* Zap last space */ } -#if defined(__GNUC__) && !defined(__clang__) +#if defined(__GNUC__) && !defined(__clang__) && __GNUC__ >= 7 #pragma GCC diagnostic pop #endif #endif /*ZINT_TEST*/ diff --git a/backend/common.h b/backend/common.h index 83a280e4..5e10af4f 100644 --- a/backend/common.h +++ b/backend/common.h @@ -1,7 +1,7 @@ /* common.h - Header for all common functions in common.c */ /* libzint - the open source barcode library - Copyright (C) 2009-2023 Robin Stuart + Copyright (C) 2009-2024 Robin Stuart Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions @@ -54,7 +54,7 @@ extern "C" { # include # define z_alloca(nmemb) _alloca(nmemb) #else -# if defined(ZINT_IS_C89) || defined(ZINT_IS_C99) || defined(__NuttX__) /* C89 or C99 or NuttX RTOS */ +# if defined(ZINT_IS_C89) || defined(ZINT_IS_C99) || defined(__NuttX__) || defined(_AIX) # include # endif # define z_alloca(nmemb) alloca(nmemb) diff --git a/backend/output.h b/backend/output.h index 7bdb3f27..6ff52fab 100644 --- a/backend/output.h +++ b/backend/output.h @@ -105,8 +105,8 @@ INTERNAL FILE *out_win_fopen(const char *filename, const char *mode); #define out_le_float(b, n) do { \ unsigned char *bp = (unsigned char *) &(b); \ - float f = n; \ - uint32_t *p_u32 = (uint32_t *) &(f); \ + float f = (float) (n); \ + uint32_t *p_u32 = (uint32_t *) &f; \ bp[0] = (unsigned char) (*p_u32 & 0xFF); \ bp[1] = (unsigned char) ((*p_u32 >> 8) & 0xFF); \ bp[2] = (unsigned char) ((*p_u32 >> 16) & 0xFF); \ diff --git a/backend/tests/test_large.c b/backend/tests/test_large.c index 022151c1..4bba4f3f 100644 --- a/backend/tests/test_large.c +++ b/backend/tests/test_large.c @@ -1,6 +1,6 @@ /* libzint - the open source barcode library - Copyright (C) 2020-2023 Robin Stuart + Copyright (C) 2020-2024 Robin Stuart Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions @@ -29,6 +29,8 @@ */ /* SPDX-License-Identifier: BSD-3-Clause */ +#include + #include "testcommon.h" #include "../large.h" @@ -43,7 +45,7 @@ # elif defined(__GNUC__) # pragma GCC diagnostic ignored "-Wformat" /* Unfortunately doesn't seem to be way to only avoid non-ISO warnings */ # endif -#elif defined(_MSC_VER) || defined(__APPLE__) || defined(__OpenBSD__) || __WORDSIZE == 32 +#elif (defined(__WORDSIZE) && __WORDSIZE == 32) || (defined(ULONG_MAX) && ULONG_MAX <= 0xFFFFFFFF) # define LX_FMT "ll" #else # define LX_FMT "l" diff --git a/backend/tests/test_library.c b/backend/tests/test_library.c index 83803b76..16224543 100644 --- a/backend/tests/test_library.c +++ b/backend/tests/test_library.c @@ -1,6 +1,6 @@ /* libzint - the open source barcode library - Copyright (C) 2019-2023 Robin Stuart + Copyright (C) 2019-2024 Robin Stuart Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions @@ -945,19 +945,18 @@ 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__ +#if defined(__NetBSD__) || defined(_AIX) /* Reading a directory works on NetBSD, and get `code128()` ZINT_ERROR_TOO_LONG instead */ - testSkip("Test not implemented on NetBSD"); + (void)ret; (void)symbol; (void)dirname; + testSkip("Test not implemented on NetBSD or AIX"); #else symbol = ZBarcode_Create(); assert_nonnull(symbol, "Symbol not created\n"); diff --git a/backend/tests/testcommon.c b/backend/tests/testcommon.c index 4876c0d9..2458a4b0 100644 --- a/backend/tests/testcommon.c +++ b/backend/tests/testcommon.c @@ -1,6 +1,6 @@ /* libzint - the open source barcode library - Copyright (C) 2019-2023 Robin Stuart + Copyright (C) 2019-2024 Robin Stuart Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions @@ -1590,7 +1590,7 @@ int testUtilCmpPngs(const char *png1, const char *png2) { int width1, height1, width2, height2; png_byte color_type1, color_type2; png_byte bit_depth1, bit_depth2; - png_bytep row1 = NULL, row2 = NULL; + png_bytep row1, row2; size_t rowbytes1, rowbytes2; int r; @@ -1634,6 +1634,7 @@ int testUtilCmpPngs(const char *png1, const char *png2) { return 7; } + row1 = row2 = NULL; /* Init here to avoid potential "clobbered" warning */ if (setjmp(png_jmpbuf(png_ptr1))) { if (row1) { free(row1); @@ -4007,12 +4008,12 @@ int testUtilZXingCPPCmp(struct zint_symbol *symbol, char *msg, char *cmp_buf, in int maxi_len = 0; if (symbol->option_2 >= 1 && symbol->option_2 <= 100) { /* Suppress gcc warning null destination pointer [-Wformat-overflow=] false-positive */ -#if defined(__GNUC__) && !defined(__clang__) +#if defined(__GNUC__) && !defined(__clang__) && __GNUC__ >= 7 #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wformat-overflow=" #endif sprintf(maxi, "[)>\03601\035%02d", symbol->option_2 - 1); -#if defined(__GNUC__) && !defined(__clang__) +#if defined(__GNUC__) && !defined(__clang__) && __GNUC__ >= 7 #pragma GCC diagnostic pop #endif maxi_len = (int) strlen(maxi); diff --git a/frontend/main.c b/frontend/main.c index bae9efb1..cf731439 100644 --- a/frontend/main.c +++ b/frontend/main.c @@ -25,19 +25,20 @@ #include #include -#ifndef _MSC_VER +#if !defined(_MSC_VER) && !defined(__NetBSD__) && !defined(_AIX) # include -# if defined(__NetBSD__) && !defined(getopt_long_only) /* `getopt_long_only()` not available */ -# define getopt_long_only getopt_long -# endif # include #else # include "../getopt/getopt.h" -# include "zint.h" -# if _MSC_VER != 1200 /* VC6 */ -# pragma warning(disable: 4996) /* function or variable may be unsafe */ +# ifdef _MSC_VER +# include "zint.h" +# if _MSC_VER != 1200 /* VC6 */ +# pragma warning(disable: 4996) /* function or variable may be unsafe */ +# endif +# else +# include # endif -#endif /* _MSC_VER */ +#endif /* Following copied from "backend/library.c" */ @@ -64,7 +65,7 @@ typedef char static_assert_int_at_least_32bits[sizeof(int) * CHAR_BIT < 32 ? -1 # include # define z_alloca(nmemb) _alloca(nmemb) #else -# if defined(ZINT_IS_C89) || defined(ZINT_IS_C99) || defined(__NuttX__) /* C89 or C99 or NuttX RTOS */ +# if defined(ZINT_IS_C89) || defined(ZINT_IS_C99) || defined(__NuttX__) || defined(_AIX) # include # endif # define z_alloca(nmemb) alloca(nmemb) diff --git a/frontend/tests/test_args.c b/frontend/tests/test_args.c index 47b85d99..67d6f220 100644 --- a/frontend/tests/test_args.c +++ b/frontend/tests/test_args.c @@ -1,6 +1,6 @@ /* libzint - the open source barcode library - Copyright (C) 2020-2023 Robin Stuart + Copyright (C) 2020-2024 Robin Stuart Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions @@ -1245,9 +1245,6 @@ static void test_other_opts(const testCtx *const p_ctx) { for (i = 0; i < data_size; i++) { if (testContinue(p_ctx, i)) continue; -#ifdef __NetBSD__ - if (strcmp(data[i].opt, " -bg=") == 0) continue; /* `getopt_long_only()` not available on NetBSD */ -#endif strcpy(cmd, "zint");