mirror of
https://github.com/curl/curl.git
synced 2025-01-06 13:44:52 +08:00
84338c4de2
Enable more picky compiler warnings. I've found these options in the nghttp3 project when implementing the CMake quick picky warning functionality for it [1]. `-Wunused-macros` was too noisy to keep around, but fixed a few issues it revealed while testing. - autotools: reflect the more precisely-versioned clang warnings. Follow-up to033f8e2a08
#12324 - autotools: sync between clang and gcc the way we set `no-multichar`. - autotools: avoid setting `-Wstrict-aliasing=3` twice. - autotools: disable `-Wmissing-noreturn` for MSYS gcc targets [2]. It triggers in libtool-generated stub code. - lib/timeval: delete a redundant `!MSDOS` guard from a `WIN32` branch. - lib/curl_setup.h: delete duplicate declaration for `fileno`. Added in initial commitae1912cb0d
(1999-12-29). This suggests this may not be needed anymore, but if it does, we may restore this for those specific (non-Windows) systems. - lib: delete unused macro `FTP_BUFFER_ALLOCSIZE` sincec1d6fe2aaa
. - lib: delete unused macro `isxdigit_ascii` sincef65f750742
. - lib/mqtt: delete unused macro `MQTT_HEADER_LEN`. - lib/multi: delete unused macro `SH_READ`/`SH_WRITE`. - lib/hostip: add `noreturn` function attribute via new `CURL_NORETURN` macro. - lib/mprintf: delete duplicate declaration for `Curl_dyn_vprintf`. - lib/rand: fix `-Wunreachable-code` and related fallouts [3]. - lib/setopt: fix `-Wunreachable-code-break`. - lib/system_win32 and lib/timeval: fix double declarations for `Curl_freq` and `Curl_isVistaOrGreater` in CMake UNITY mode [4]. - lib/warnless: fix double declarations in CMake UNITY mode [5]. This was due to force-disabling the header guard of `warnless.h` to to reapply it to source code coming after `warnless.c` in UNITY builds. This reapplied declarations too, causing the warnings. Solved by adding a header guard for the lines that actually need to be reapplied. - lib/vauth/digest: fix `-Wunreachable-code-break` [6]. - lib/vssh/libssh2: fix `-Wunreachable-code-break` and delete redundant block. - lib/vtls/sectransp: fix `-Wunreachable-code-break` [7]. - lib/vtls/sectransp: suppress `-Wunreachable-code`. Detected in `else` branches of dynamic feature checks, with results known at compile-time, e.g. ```c if(SecCertificateCopySubjectSummary) /* -> true */ ``` Likely fixable as a separate micro-project, but given SecureTransport is deprecated anyway, let's just silence these locally. - src/tool_help: delete duplicate declaration for `helptext`. - src/tool_xattr: fix `-Wunreachable-code`. - tests: delete duplicate declaration for `unitfail` [8]. - tests: delete duplicate declaration for `strncasecompare`. - tests/libtest: delete duplicate declaration for `gethostname`. Originally added in687df5c8c3
(2010-08-02). Got complicated later:c49e9683b8
If there are still systems around with warnings, we may restore the prototype, but limited for those systems. - tests/lib2305: delete duplicate declaration for `libtest_debug_config`. - tests/h2-download: fix `-Wunreachable-code-break`. [1]a70edb08e9/cmake/PickyWarningsC.cmake
[2] https://ci.appveyor.com/project/curlorg/curl/builds/48553586/job/3qkgjauiqla5fj45?fullLog=true#L1675 [3] https://github.com/curl/curl/actions/runs/6880886309/job/18716044703?pr=12331#step:7:72 https://github.com/curl/curl/actions/runs/6883016087/job/18722707368?pr=12331#step:7:109 [4] https://ci.appveyor.com/project/curlorg/curl/builds/48555101/job/9g15qkrriklpf1ut#L204 [5] https://ci.appveyor.com/project/curlorg/curl/builds/48555101/job/9g15qkrriklpf1ut#L218 [6] https://github.com/curl/curl/actions/runs/6880886309/job/18716042927?pr=12331#step:7:290 [7] https://github.com/curl/curl/actions/runs/6891484996/job/18746659406?pr=12331#step:9:1193 [8] https://github.com/curl/curl/actions/runs/6882803986/job/18722082562?pr=12331#step:33:1870 Closes #12331
112 lines
5.4 KiB
C
112 lines
5.4 KiB
C
/***************************************************************************
|
|
* _ _ ____ _
|
|
* Project ___| | | | _ \| |
|
|
* / __| | | | |_) | |
|
|
* | (__| |_| | _ <| |___
|
|
* \___|\___/|_| \_\_____|
|
|
*
|
|
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
|
|
*
|
|
* This software is licensed as described in the file COPYING, which
|
|
* you should have received as part of this distribution. The terms
|
|
* are also available at https://curl.se/docs/copyright.html.
|
|
*
|
|
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
|
* copies of the Software, and permit persons to whom the Software is
|
|
* furnished to do so, under the terms of the COPYING file.
|
|
*
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
* KIND, either express or implied.
|
|
*
|
|
* SPDX-License-Identifier: curl
|
|
*
|
|
***************************************************************************/
|
|
#include "test.h"
|
|
|
|
/* The fail macros mark the current test step as failed, and continue */
|
|
#define fail_if(expr, msg) \
|
|
do { \
|
|
if(expr) { \
|
|
fprintf(stderr, "%s:%d FAILED Assertion '%s' met: %s\n", \
|
|
__FILE__, __LINE__, #expr, msg); \
|
|
unitfail++; \
|
|
} \
|
|
} while(0)
|
|
|
|
#define fail_unless(expr, msg) \
|
|
do { \
|
|
if(!(expr)) { \
|
|
fprintf(stderr, "%s:%d Assertion '%s' FAILED: %s\n", \
|
|
__FILE__, __LINE__, #expr, msg); \
|
|
unitfail++; \
|
|
} \
|
|
} while(0)
|
|
|
|
#define verify_memory(dynamic, check, len) \
|
|
do { \
|
|
if(dynamic && memcmp(dynamic, check, len)) { \
|
|
fprintf(stderr, "%s:%d Memory buffer FAILED match size %d. " \
|
|
"'%s' is not\n", __FILE__, __LINE__, len, \
|
|
hexdump((const unsigned char *)check, len)); \
|
|
fprintf(stderr, "%s:%d the same as '%s'\n", __FILE__, __LINE__, \
|
|
hexdump((const unsigned char *)dynamic, len)); \
|
|
unitfail++; \
|
|
} \
|
|
} while(0)
|
|
|
|
/* fail() is for when the test case figured out by itself that a check
|
|
proved a failure */
|
|
#define fail(msg) do { \
|
|
fprintf(stderr, "%s:%d test FAILED: '%s'\n", \
|
|
__FILE__, __LINE__, msg); \
|
|
unitfail++; \
|
|
} while(0)
|
|
|
|
|
|
/* The abort macros mark the current test step as failed, and exit the test */
|
|
#define abort_if(expr, msg) \
|
|
do { \
|
|
if(expr) { \
|
|
fprintf(stderr, "%s:%d ABORT assertion '%s' met: %s\n", \
|
|
__FILE__, __LINE__, #expr, msg); \
|
|
unitfail++; \
|
|
goto unit_test_abort; \
|
|
} \
|
|
} while(0)
|
|
|
|
#define abort_unless(expr, msg) \
|
|
do { \
|
|
if(!(expr)) { \
|
|
fprintf(stderr, "%s:%d ABORT assertion '%s' failed: %s\n", \
|
|
__FILE__, __LINE__, #expr, msg); \
|
|
unitfail++; \
|
|
goto unit_test_abort; \
|
|
} \
|
|
} while(0)
|
|
|
|
#define abort_test(msg) \
|
|
do { \
|
|
fprintf(stderr, "%s:%d test ABORTED: '%s'\n", \
|
|
__FILE__, __LINE__, msg); \
|
|
unitfail++; \
|
|
goto unit_test_abort; \
|
|
} while(0)
|
|
|
|
|
|
#define UNITTEST_START \
|
|
int test(char *arg) \
|
|
{ \
|
|
(void)arg; \
|
|
if(unit_setup()) { \
|
|
fail("unit_setup() FAILURE"); \
|
|
} \
|
|
else {
|
|
|
|
#define UNITTEST_STOP \
|
|
goto unit_test_abort; /* avoid warning */ \
|
|
unit_test_abort: \
|
|
unit_stop(); \
|
|
} \
|
|
return unitfail; \
|
|
}
|