From: Viktor Szakats Date: Mon, 17 Mar 2025 23:39:57 +0000 (+0100) Subject: cmake: fix clang-tidy builds to verify tests, fix fallouts X-Git-Tag: curl-8_13_0~88 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9465327084c920deee7ba5abbcd55dbec6cf3e95;p=thirdparty%2Fcurl.git cmake: fix clang-tidy builds to verify tests, fix fallouts - cmake: disable test bundles for clang-tidy builds. clang-tidy ignores #included .c sources, and incompatible with unity and bundles. It caused clang-tidy ignoring all test sources. It also means this is the first time tests sources are checked with clang-tidy. (autotools doesn't run it on tests.) - cmake: update description for `CURL_TEST_BUNDLES` option. - fix tests using special `CURLE_*` enums that were missing from `curl/curl.h`. Add them as reserved codes. - fix about ~50 other issues detected by clang-tidy: unchecked results, NULL derefs, memory leaks, casts to enums, unused assigments, uninitialized `errno` uses, unchecked `open`, indent, and more. - drop unnecessary casts (lib1533, lib3207). - suppress a few impossible cases with detailed `NOLINT`s. - lib/escape.c: drop `NOLINT` no longer necessary. Follow-up to 72abf7c13a479edcde80afa60faad3f35f672c0b #13862 (possibly) - extend two existing `NOLINT` comments with details. Follow-up to fabfa8e4024473035b3e5c3c30c330be726d9bb4 #15825 Closes #16756 --- diff --git a/CMakeLists.txt b/CMakeLists.txt index fcbd3426c8..8e04ec203a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -300,9 +300,14 @@ if(ENABLE_CURLDEBUG) list(APPEND CURL_DEBUG_MACROS "CURLDEBUG") endif() +option(CURL_TEST_BUNDLES "Build tests into single-binary bundles" OFF) + option(CURL_CLANG_TIDY "Run the build through clang-tidy" OFF) if(CURL_CLANG_TIDY) + # clang-tidy is not looking into #included sources, thus not compatible with + # unity builds and test bundles. set(CMAKE_UNITY_BUILD OFF) + set(CURL_TEST_BUNDLES OFF) set(_tidy_checks "") list(APPEND _tidy_checks "-clang-analyzer-security.insecureAPI.strcpy") list(APPEND _tidy_checks "-clang-analyzer-optin.performance.Padding") diff --git a/docs/INSTALL-CMAKE.md b/docs/INSTALL-CMAKE.md index 38d1fec1ba..5375ef11f1 100644 --- a/docs/INSTALL-CMAKE.md +++ b/docs/INSTALL-CMAKE.md @@ -240,7 +240,7 @@ target_link_libraries(my_target PRIVATE CURL::libcurl) - `CURL_LTO`: Enable compiler Link Time Optimizations. Default: `OFF` - `CURL_STATIC_CRT`: Build libcurl with static CRT with MSVC (`/MT`) (requires UCRT, static libcurl or no curl executable). Default: `OFF` - `CURL_TARGET_WINDOWS_VERSION`: Minimum target Windows version as hex string. -- `CURL_TEST_BUNDLES`: Bundle `libtest` and `unittest` tests into single binaries. Default: `OFF` +- `CURL_TEST_BUNDLES`: Build tests into single-binary bundles. Default: `OFF` - `CURL_WERROR`: Turn compiler warnings into errors. Default: `OFF` - `ENABLE_CURLDEBUG`: Enable TrackMemory debug feature. Default: =`ENABLE_DEBUG` - `ENABLE_CURL_MANUAL`: Build the man page for curl and enable its `-M`/`--manual` option. Default: `ON` diff --git a/include/curl/curl.h b/include/curl/curl.h index 81dbab3791..84966e81e4 100644 --- a/include/curl/curl.h +++ b/include/curl/curl.h @@ -645,7 +645,20 @@ typedef enum { CURLE_UNRECOVERABLE_POLL, /* 99 - poll/select returned fatal error */ CURLE_TOO_LARGE, /* 100 - a value/data met its maximum */ CURLE_ECH_REQUIRED, /* 101 - ECH tried but failed */ - CURL_LAST /* never use! */ + CURL_LAST, /* never use! */ + + CURLE_RESERVED115 = 115, /* 115-126 - used in tests */ + CURLE_RESERVED116 = 116, + CURLE_RESERVED117 = 117, + CURLE_RESERVED118 = 118, + CURLE_RESERVED119 = 119, + CURLE_RESERVED120 = 120, + CURLE_RESERVED121 = 121, + CURLE_RESERVED122 = 122, + CURLE_RESERVED123 = 123, + CURLE_RESERVED124 = 124, + CURLE_RESERVED125 = 125, + CURLE_RESERVED126 = 126 } CURLcode; #ifndef CURL_NO_OLDIES /* define this to test if your app builds with all diff --git a/lib/cf-socket.c b/lib/cf-socket.c index e02b035127..eeea77acec 100644 --- a/lib/cf-socket.c +++ b/lib/cf-socket.c @@ -1828,7 +1828,9 @@ static CURLcode cf_udp_setup_quic(struct Curl_cfilter *cf, /* QUIC needs a connected socket, nonblocking */ DEBUGASSERT(ctx->sock != CURL_SOCKET_BAD); - rc = connect(ctx->sock, &ctx->addr.curl_sa_addr, /* NOLINT */ + /* error: The 1st argument to 'connect' is -1 but should be >= 0 + NOLINTNEXTLINE(clang-analyzer-unix.StdCLibraryFunctions) */ + rc = connect(ctx->sock, &ctx->addr.curl_sa_addr, (curl_socklen_t)ctx->addr.addrlen); if(-1 == rc) { return socket_connect_result(data, ctx->ip.remote_ip, SOCKERRNO); diff --git a/lib/escape.c b/lib/escape.c index eaad6d33ad..0afc96fc01 100644 --- a/lib/escape.c +++ b/lib/escape.c @@ -223,8 +223,6 @@ void Curl_hexencode(const unsigned char *src, size_t len, /* input length */ DEBUGASSERT(src && len && (olen >= 3)); if(src && len && (olen >= 3)) { while(len-- && (olen >= 3)) { - /* clang-tidy warns on this line without this comment: */ - /* NOLINTNEXTLINE(clang-analyzer-core.UndefinedBinaryOperatorResult) */ *out++ = (unsigned char)hex[(*src & 0xF0) >> 4]; *out++ = (unsigned char)hex[*src & 0x0F]; ++src; diff --git a/lib/mprintf.c b/lib/mprintf.c index 16b30bf4b9..bedd3615cb 100644 --- a/lib/mprintf.c +++ b/lib/mprintf.c @@ -993,7 +993,9 @@ number: /* NOTE NOTE NOTE!! Not all sprintf implementations return number of output characters */ #ifdef HAVE_SNPRINTF - (snprintf)(work, BUFFSIZE, formatbuf, iptr->val.dnum); /* NOLINT */ + /* !checksrc! disable LONGLINE */ + /* NOLINTNEXTLINE(clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling) */ + (snprintf)(work, BUFFSIZE, formatbuf, iptr->val.dnum); #ifdef _WIN32 /* Old versions of the Windows CRT do not terminate the snprintf output buffer if it reaches the max size so we do that here. */ diff --git a/lib/strerror.c b/lib/strerror.c index abbdb857e3..564b197e5d 100644 --- a/lib/strerror.c +++ b/lib/strerror.c @@ -335,6 +335,20 @@ curl_easy_strerror(CURLcode error) case CURLE_OBSOLETE62: case CURLE_OBSOLETE75: case CURLE_OBSOLETE76: + + /* error codes used by curl tests */ + case CURLE_RESERVED115: + case CURLE_RESERVED116: + case CURLE_RESERVED117: + case CURLE_RESERVED118: + case CURLE_RESERVED119: + case CURLE_RESERVED120: + case CURLE_RESERVED121: + case CURLE_RESERVED122: + case CURLE_RESERVED123: + case CURLE_RESERVED124: + case CURLE_RESERVED125: + case CURLE_RESERVED126: case CURL_LAST: break; } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 295750c85b..306aa240a8 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -21,8 +21,6 @@ # SPDX-License-Identifier: curl # ########################################################################### -option(CURL_TEST_BUNDLES "Bundle libtest and unittest tests into single binaries" OFF) - find_program(TEST_NGHTTPX "nghttpx") if(NOT TEST_NGHTTPX) set(TEST_NGHTTPX "nghttpx") diff --git a/tests/libtest/lib1301.c b/tests/libtest/lib1301.c index de3aaeac6a..39ba7dc1fc 100644 --- a/tests/libtest/lib1301.c +++ b/tests/libtest/lib1301.c @@ -28,7 +28,7 @@ if(!(expr)) { \ fprintf(stderr, "%s:%d Assertion '%s' failed: %s\n", \ __FILE__, __LINE__, #expr, msg); \ - return (CURLcode)1; \ + return TEST_ERR_FAILURE; \ } \ } while(0) diff --git a/tests/libtest/lib1501.c b/tests/libtest/lib1501.c index ced1d5d987..34b4ea7ada 100644 --- a/tests/libtest/lib1501.c +++ b/tests/libtest/lib1501.c @@ -96,7 +96,7 @@ CURLcode test(char *URL) fprintf(stderr, "pong = %ld\n", e); if(e > MAX_BLOCKED_TIME_MS) { - res = (CURLcode) 100; + res = CURLE_TOO_LARGE; break; } } diff --git a/tests/libtest/lib1517.c b/tests/libtest/lib1517.c index 3957eb1990..571b7585af 100644 --- a/tests/libtest/lib1517.c +++ b/tests/libtest/lib1517.c @@ -64,7 +64,8 @@ CURLcode test(char *URL) #if (defined(_WIN32) || defined(__CYGWIN__)) printf("Windows TCP does not deliver response data but reports " "CONNABORTED\n"); - return (CURLcode)1; /* skip since it fails on Windows without workaround */ + return TEST_ERR_FAILURE; /* skip since it fails on Windows without + workaround */ #else return CURLE_OK; /* sure, run this! */ #endif diff --git a/tests/libtest/lib1518.c b/tests/libtest/lib1518.c index 560d79ce23..5588ea098a 100644 --- a/tests/libtest/lib1518.c +++ b/tests/libtest/lib1518.c @@ -76,6 +76,8 @@ CURLcode test(char *URL) /* Perform the request, res will get the return code */ res = curl_easy_perform(curl); + if(res) + goto test_cleanup; curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &curlResponseCode); curl_easy_getinfo(curl, CURLINFO_REDIRECT_COUNT, &curlRedirectCount); diff --git a/tests/libtest/lib1533.c b/tests/libtest/lib1533.c index e1dd16c9ce..4f0a39e8aa 100644 --- a/tests/libtest/lib1533.c +++ b/tests/libtest/lib1533.c @@ -98,8 +98,9 @@ static size_t write_callback(char *ptr, size_t size, size_t nmemb, } -static int perform_and_check_connections(CURL *curl, const char *description, - long expected_connections) +static CURLcode perform_and_check_connections(CURL *curl, + const char *description, + long expected_connections) { CURLcode res; long connections = 0; @@ -132,7 +133,7 @@ CURLcode test(char *URL) struct cb_data data; CURL *curl = NULL; CURLcode res = TEST_ERR_FAILURE; - int result; + CURLcode result; if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { fprintf(stderr, "curl_global_init() failed\n"); @@ -161,7 +162,7 @@ CURLcode test(char *URL) result = perform_and_check_connections(curl, "First request without CURLOPT_KEEP_SENDING_ON_ERROR", 1); if(result != TEST_ERR_SUCCESS) { - res = (CURLcode) result; + res = result; goto test_cleanup; } @@ -170,7 +171,7 @@ CURLcode test(char *URL) result = perform_and_check_connections(curl, "Second request without CURLOPT_KEEP_SENDING_ON_ERROR", 1); if(result != TEST_ERR_SUCCESS) { - res = (CURLcode) result; + res = result; goto test_cleanup; } @@ -181,7 +182,7 @@ CURLcode test(char *URL) result = perform_and_check_connections(curl, "First request with CURLOPT_KEEP_SENDING_ON_ERROR", 1); if(result != TEST_ERR_SUCCESS) { - res = (CURLcode) result; + res = result; goto test_cleanup; } @@ -190,7 +191,7 @@ CURLcode test(char *URL) result = perform_and_check_connections(curl, "Second request with CURLOPT_KEEP_SENDING_ON_ERROR", 0); if(result != TEST_ERR_SUCCESS) { - res = (CURLcode) result; + res = result; goto test_cleanup; } diff --git a/tests/libtest/lib1538.c b/tests/libtest/lib1538.c index ebc68573f1..bd830b2830 100644 --- a/tests/libtest/lib1538.c +++ b/tests/libtest/lib1538.c @@ -34,6 +34,7 @@ CURLcode test(char *URL) CURLUcode urlret; (void)URL; + /* NOLINTBEGIN(clang-analyzer-optin.core.EnumCastOutOfRange) */ curl_easy_strerror((CURLcode)INT_MAX); curl_multi_strerror((CURLMcode)INT_MAX); curl_share_strerror((CURLSHcode)INT_MAX); @@ -42,6 +43,7 @@ CURLcode test(char *URL) curl_multi_strerror((CURLMcode)-INT_MAX); curl_share_strerror((CURLSHcode)-INT_MAX); curl_url_strerror((CURLUcode)-INT_MAX); + /* NOLINTEND(clang-analyzer-optin.core.EnumCastOutOfRange) */ for(easyret = CURLE_OK; easyret <= CURL_LAST; easyret++) { printf("e%d: %s\n", (int)easyret, curl_easy_strerror(easyret)); } diff --git a/tests/libtest/lib1559.c b/tests/libtest/lib1559.c index 37c0b8aace..0d1a450ac0 100644 --- a/tests/libtest/lib1559.c +++ b/tests/libtest/lib1559.c @@ -32,19 +32,22 @@ CURLcode test(char *URL) { CURLcode res = CURLE_OK; CURL *curl = NULL; - char *longurl = malloc(EXCESSIVE); + char *longurl = NULL; CURLU *u; (void)URL; - if(!longurl) - return (CURLcode)1; + global_init(CURL_GLOBAL_ALL); + easy_init(curl); + + longurl = malloc(EXCESSIVE); + if(!longurl) { + res = TEST_ERR_MAJOR_BAD; + goto test_cleanup; + } memset(longurl, 'a', EXCESSIVE); longurl[EXCESSIVE-1] = 0; - global_init(CURL_GLOBAL_ALL); - easy_init(curl); - res = curl_easy_setopt(curl, CURLOPT_URL, longurl); printf("CURLOPT_URL %d bytes URL == %d\n", EXCESSIVE, res); diff --git a/tests/libtest/lib1560.c b/tests/libtest/lib1560.c index 95971ec7a5..9f24ff53a7 100644 --- a/tests/libtest/lib1560.c +++ b/tests/libtest/lib1560.c @@ -1128,6 +1128,7 @@ static CURLUPart part2id(char *part) return CURLUPART_FRAGMENT; if(!strcmp("zoneid", part)) return CURLUPART_ZONEID; + /* NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange) */ return (CURLUPart)9999; /* bad input => bad output */ } diff --git a/tests/libtest/lib1597.c b/tests/libtest/lib1597.c index fa09e71d6c..1b7285d0dc 100644 --- a/tests/libtest/lib1597.c +++ b/tests/libtest/lib1597.c @@ -37,7 +37,6 @@ CURLcode test(char *URL) { CURL *curl = NULL; CURLcode res = CURLE_OK; - CURLcode result = CURLE_OK; curl_version_info_data *curlinfo; const char *const *proto; int n; @@ -97,9 +96,9 @@ CURLcode test(char *URL) /* Run the tests. */ for(i = 0; prots[i].in; i++) { - result = curl_easy_setopt(curl, CURLOPT_PROTOCOLS_STR, prots[i].in); - if(result != *prots[i].exp) { - printf("unexpectedly '%s' returned %d\n", prots[i].in, result); + res = curl_easy_setopt(curl, CURLOPT_PROTOCOLS_STR, prots[i].in); + if(res != *prots[i].exp) { + printf("unexpectedly '%s' returned %d\n", prots[i].in, res); break; } } @@ -109,5 +108,5 @@ test_cleanup: curl_easy_cleanup(curl); curl_global_cleanup(); - return result; + return res; } diff --git a/tests/libtest/lib1905.c b/tests/libtest/lib1905.c index bba0400cbb..df35de18b2 100644 --- a/tests/libtest/lib1905.c +++ b/tests/libtest/lib1905.c @@ -40,7 +40,7 @@ CURLcode test(char *URL) cm = curl_multi_init(); if(!cm) { curl_global_cleanup(); - return (CURLcode)1; + return TEST_ERR_MULTI; } sh = curl_share_init(); if(!sh) diff --git a/tests/libtest/lib1911.c b/tests/libtest/lib1911.c index 0fd62a8b92..4177ed0b37 100644 --- a/tests/libtest/lib1911.c +++ b/tests/libtest/lib1911.c @@ -44,7 +44,7 @@ CURLcode test(char *URL) easy = curl_easy_init(); if(!easy) { curl_global_cleanup(); - return (CURLcode)1; + return TEST_ERR_EASY_INIT; } /* make it a null-terminated C string with just As */ diff --git a/tests/libtest/lib2302.c b/tests/libtest/lib2302.c index ccf8dfb587..c83a04c783 100644 --- a/tests/libtest/lib2302.c +++ b/tests/libtest/lib2302.c @@ -98,32 +98,31 @@ CURLcode test(char *URL) CURL *curl; CURLcode res = CURLE_OK; struct ws_data ws_data; - memset(&ws_data, 0, sizeof(ws_data)); - - ws_data.buf = (char *)calloc(LIB2302_BUFSIZE, 1); - if(!ws_data.buf) - return res; global_init(CURL_GLOBAL_ALL); - curl = curl_easy_init(); - if(curl) { - ws_data.easy = curl; - - curl_easy_setopt(curl, CURLOPT_URL, URL); - /* use the callback style */ - curl_easy_setopt(curl, CURLOPT_USERAGENT, "webbie-sox/3"); - curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); - curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writecb); - curl_easy_setopt(curl, CURLOPT_WRITEDATA, &ws_data); - res = curl_easy_perform(curl); - fprintf(stderr, "curl_easy_perform() returned %d\n", res); - /* always cleanup */ - curl_easy_cleanup(curl); - flush_data(&ws_data); + memset(&ws_data, 0, sizeof(ws_data)); + ws_data.buf = (char *)calloc(LIB2302_BUFSIZE, 1); + if(ws_data.buf) { + curl = curl_easy_init(); + if(curl) { + ws_data.easy = curl; + + curl_easy_setopt(curl, CURLOPT_URL, URL); + /* use the callback style */ + curl_easy_setopt(curl, CURLOPT_USERAGENT, "webbie-sox/3"); + curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writecb); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, &ws_data); + res = curl_easy_perform(curl); + fprintf(stderr, "curl_easy_perform() returned %d\n", res); + /* always cleanup */ + curl_easy_cleanup(curl); + flush_data(&ws_data); + } + free(ws_data.buf); } curl_global_cleanup(); - free(ws_data.buf); return res; } diff --git a/tests/libtest/lib3026.c b/tests/libtest/lib3026.c index dd3732b465..287adde8a0 100644 --- a/tests/libtest/lib3026.c +++ b/tests/libtest/lib3026.c @@ -55,7 +55,7 @@ CURLcode test(char *URL) CURLcode results[NUM_THREADS]; curl_win_thread_handle_t ths[NUM_THREADS]; unsigned tid_count = NUM_THREADS, i; - int test_failure = 0; + CURLcode test_failure = CURLE_OK; curl_version_info_data *ver; (void) URL; @@ -64,7 +64,7 @@ CURLcode test(char *URL) fprintf(stderr, "%s:%d On Windows but the " "CURL_VERSION_THREADSAFE feature flag is not set\n", __FILE__, __LINE__); - return (CURLcode)-1; + return TEST_ERR_MAJOR_BAD; } /* On Windows libcurl global init/cleanup calls LoadLibrary/FreeLibrary for @@ -87,7 +87,7 @@ CURLcode test(char *URL) fprintf(stderr, "%s:%d Couldn't create thread, errno %lu\n", __FILE__, __LINE__, GetLastError()); tid_count = i; - test_failure = -1; + test_failure = TEST_ERR_MAJOR_BAD; goto cleanup; } ths[i] = th; @@ -101,11 +101,11 @@ cleanup: fprintf(stderr, "%s:%d thread[%u]: curl_global_init() failed," "with code %d (%s)\n", __FILE__, __LINE__, i, (int) results[i], curl_easy_strerror(results[i])); - test_failure = -1; + test_failure = TEST_ERR_MAJOR_BAD; } } - return (CURLcode)test_failure; + return test_failure; } #elif defined(HAVE_PTHREAD_H) @@ -137,7 +137,7 @@ CURLcode test(char *URL) fprintf(stderr, "%s:%d Have pthread but the " "CURL_VERSION_THREADSAFE feature flag is not set\n", __FILE__, __LINE__); - return (CURLcode)-1; + return TEST_ERR_MAJOR_BAD; } for(i = 0; i < tid_count; i++) { @@ -148,7 +148,7 @@ CURLcode test(char *URL) fprintf(stderr, "%s:%d Couldn't create thread, errno %d\n", __FILE__, __LINE__, res); tid_count = i; - test_failure = (CURLcode)-1; + test_failure = TEST_ERR_MAJOR_BAD; goto cleanup; } } @@ -160,7 +160,7 @@ cleanup: fprintf(stderr, "%s:%d thread[%u]: curl_global_init() failed," "with code %d (%s)\n", __FILE__, __LINE__, i, (int) results[i], curl_easy_strerror(results[i])); - test_failure = (CURLcode)-1; + test_failure = TEST_ERR_MAJOR_BAD; } } @@ -178,7 +178,7 @@ CURLcode test(char *URL) fprintf(stderr, "%s:%d No pthread but the " "CURL_VERSION_THREADSAFE feature flag is set\n", __FILE__, __LINE__); - return (CURLcode)-1; + return TEST_ERR_MAJOR_BAD; } return CURLE_OK; } diff --git a/tests/libtest/lib3207.c b/tests/libtest/lib3207.c index e2c0233fb2..adb31aa264 100644 --- a/tests/libtest/lib3207.c +++ b/tests/libtest/lib3207.c @@ -41,7 +41,7 @@ struct Ctx { const char *URL; CURLSH *share; - int result; + CURLcode result; int thread_id; struct curl_slist *contents; }; @@ -120,7 +120,7 @@ test_thread(void *ptr) } test_cleanup: - ctx->result = (int)res; + ctx->result = res; return 0; } @@ -186,7 +186,7 @@ static void execute(CURLSH *share, struct Ctx *ctx) CURLcode test(char *URL) { - int res = 0; + CURLcode res = CURLE_OK; int i; CURLSH* share; struct Ctx ctx[THREAD_SIZE]; @@ -203,7 +203,7 @@ CURLcode test(char *URL) ctx[i].share = share; ctx[i].URL = URL; ctx[i].thread_id = i; - ctx[i].result = 0; + ctx[i].result = CURLE_OK; ctx[i].contents = NULL; } @@ -227,5 +227,5 @@ test_cleanup: if(share) curl_share_cleanup(share); curl_global_cleanup(); - return (CURLcode)res; + return res; } diff --git a/tests/libtest/lib506.c b/tests/libtest/lib506.c index 03eb11ddda..57b7f67fd0 100644 --- a/tests/libtest/lib506.c +++ b/tests/libtest/lib506.c @@ -261,8 +261,6 @@ CURLcode test(char *URL) curl_easy_cleanup(curl); - res = CURLE_OK; - /* start treads */ for(i = 1; i <= THREADS; i++) { @@ -328,6 +326,8 @@ CURLcode test(char *URL) printf("CURLOPT_COOKIELIST RELOAD\n"); test_setopt(curl, CURLOPT_COOKIELIST, "RELOAD"); + res = CURLE_OK; + code = curl_easy_getinfo(curl, CURLINFO_COOKIELIST, &cookies); if(code != CURLE_OK) { fprintf(stderr, "curl_easy_getinfo() failed\n"); diff --git a/tests/libtest/lib507.c b/tests/libtest/lib507.c index a228d08aa4..f86ee79b92 100644 --- a/tests/libtest/lib507.c +++ b/tests/libtest/lib507.c @@ -34,7 +34,7 @@ CURLcode test(char *URL) CURL *curls = NULL; CURLM *multi = NULL; int still_running; - CURLcode i = (CURLcode)-1; + CURLcode i = TEST_ERR_MAJOR_BAD; CURLcode res = CURLE_OK; CURLMsg *msg; diff --git a/tests/libtest/lib518.c b/tests/libtest/lib518.c index 289692c3f9..0aed4336a9 100644 --- a/tests/libtest/lib518.c +++ b/tests/libtest/lib518.c @@ -454,7 +454,7 @@ CURLcode test(char *URL) /* used by the test script to ask if we can run this test or not */ if(test_rlimit(FALSE)) { fprintf(stdout, "test_rlimit problem: %s\n", msgbuff); - return (CURLcode)1; + return TEST_ERR_FAILURE; } return CURLE_OK; /* sure, run this! */ } diff --git a/tests/libtest/lib537.c b/tests/libtest/lib537.c index 6e1baee7ed..2279f93b4b 100644 --- a/tests/libtest/lib537.c +++ b/tests/libtest/lib537.c @@ -465,7 +465,7 @@ CURLcode test(char *URL) /* used by the test script to ask if we can run this test or not */ if(test_rlimit(FALSE)) { fprintf(stdout, "test_rlimit problem: %s\n", msgbuff); - return (CURLcode)1; + return TEST_ERR_FAILURE; } return CURLE_OK; /* sure, run this! */ } @@ -512,7 +512,7 @@ CURLcode test(char *URL) { (void)URL; printf("system lacks necessary system function(s)"); - return (CURLcode)1; /* skip test */ + return TEST_ERR_MAJOR_BAD; /* skip test */ } #endif /* defined(HAVE_GETRLIMIT) && defined(HAVE_SETRLIMIT) */ diff --git a/tests/libtest/lib539.c b/tests/libtest/lib539.c index 2e079fae36..363d0a296b 100644 --- a/tests/libtest/lib539.c +++ b/tests/libtest/lib539.c @@ -27,60 +27,60 @@ CURLcode test(char *URL) { - CURLcode res; - CURL *curl; - char *newURL = NULL; - struct curl_slist *slist = NULL; + CURLcode res; + CURL *curl; + char *newURL = NULL; + struct curl_slist *slist = NULL; - if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { - fprintf(stderr, "curl_global_init() failed\n"); - return TEST_ERR_MAJOR_BAD; - } + if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) { + fprintf(stderr, "curl_global_init() failed\n"); + return TEST_ERR_MAJOR_BAD; + } - curl = curl_easy_init(); - if(!curl) { - fprintf(stderr, "curl_easy_init() failed\n"); - curl_global_cleanup(); - return TEST_ERR_MAJOR_BAD; - } + curl = curl_easy_init(); + if(!curl) { + fprintf(stderr, "curl_easy_init() failed\n"); + curl_global_cleanup(); + return TEST_ERR_MAJOR_BAD; + } - /* - * Begin with curl set to use a single CWD to the URL's directory. - */ - test_setopt(curl, CURLOPT_URL, URL); - test_setopt(curl, CURLOPT_VERBOSE, 1L); - test_setopt(curl, CURLOPT_FTP_FILEMETHOD, (long) CURLFTPMETHOD_SINGLECWD); + /* + * Begin with curl set to use a single CWD to the URL's directory. + */ + test_setopt(curl, CURLOPT_URL, URL); + test_setopt(curl, CURLOPT_VERBOSE, 1L); + test_setopt(curl, CURLOPT_FTP_FILEMETHOD, (long) CURLFTPMETHOD_SINGLECWD); - res = curl_easy_perform(curl); + res = curl_easy_perform(curl); + if(res == CURLE_OK) { + /* + * Change the FTP_FILEMETHOD option to use full paths rather than a CWD + * command. Use an innocuous QUOTE command, after which curl will CWD to + * ftp_conn->entrypath and then (on the next call to ftp_statemach_act) + * find a non-zero ftpconn->dirdepth even though no directories are stored + * in the ftpconn->dirs array (after a call to freedirs). + */ - /* - * Change the FTP_FILEMETHOD option to use full paths rather than a CWD - * command. Use an innocuous QUOTE command, after which curl will CWD to - * ftp_conn->entrypath and then (on the next call to ftp_statemach_act) - * find a non-zero ftpconn->dirdepth even though no directories are stored - * in the ftpconn->dirs array (after a call to freedirs). - */ + slist = curl_slist_append(NULL, "SYST"); + if(!slist) { + curl_free(newURL); + curl_easy_cleanup(curl); + curl_global_cleanup(); + return TEST_ERR_MAJOR_BAD; + } - slist = curl_slist_append(NULL, "SYST"); - if(!slist) { - curl_free(newURL); - curl_easy_cleanup(curl); - curl_global_cleanup(); - return TEST_ERR_MAJOR_BAD; - } - - test_setopt(curl, CURLOPT_URL, libtest_arg2); - test_setopt(curl, CURLOPT_FTP_FILEMETHOD, (long) CURLFTPMETHOD_NOCWD); - test_setopt(curl, CURLOPT_QUOTE, slist); - - res = curl_easy_perform(curl); + test_setopt(curl, CURLOPT_URL, libtest_arg2); + test_setopt(curl, CURLOPT_FTP_FILEMETHOD, (long) CURLFTPMETHOD_NOCWD); + test_setopt(curl, CURLOPT_QUOTE, slist); + res = curl_easy_perform(curl); + } test_cleanup: - curl_slist_free_all(slist); - curl_free(newURL); - curl_easy_cleanup(curl); - curl_global_cleanup(); + curl_slist_free_all(slist); + curl_free(newURL); + curl_easy_cleanup(curl); + curl_global_cleanup(); - return res; + return res; } diff --git a/tests/libtest/lib540.c b/tests/libtest/lib540.c index b53b955639..571f404648 100644 --- a/tests/libtest/lib540.c +++ b/tests/libtest/lib540.c @@ -206,7 +206,7 @@ CURLcode test(char *URL) start_test_timing(); if(test_argc < 4) - return (CURLcode)99; + return TEST_ERR_MAJOR_BAD; msnprintf(buffer, sizeof(buffer), "Host: %s", HOST); diff --git a/tests/libtest/lib541.c b/tests/libtest/lib541.c index 1a7a4cce39..1e221a84da 100644 --- a/tests/libtest/lib541.c +++ b/tests/libtest/lib541.c @@ -51,7 +51,7 @@ CURLcode test(char *URL) fprintf(stderr, "fopen failed with error (%d) %s\n", errno, strerror(errno)); fprintf(stderr, "Error opening file '%s'\n", libtest_arg2); - return (CURLcode)-2; /* if this happens things are major weird */ + return TEST_ERR_MAJOR_BAD; /* if this happens things are major weird */ } /* get the file size of the local file */ diff --git a/tests/libtest/lib557.c b/tests/libtest/lib557.c index ec34ed3781..85cc4e20bc 100644 --- a/tests/libtest/lib557.c +++ b/tests/libtest/lib557.c @@ -1254,21 +1254,21 @@ static int test_weird_arguments(void) int rc; /* verify %% */ - rc = curl_msnprintf(buf, sizeof(buf), "%-20d%% right? %%", 500); + (void)curl_msnprintf(buf, sizeof(buf), "%-20d%% right? %%", 500); errors += string_check(buf, "500 % right? %"); /* 100 x % */ - rc = curl_msnprintf(buf, sizeof(buf), "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" - "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" - "%%%%%%%%%%%%%%%%%%%%%%"); + (void)curl_msnprintf(buf, sizeof(buf), "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" + "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" + "%%%%%%%%%%%%%%%%%%%%%%"); /* 50 x % */ errors += string_check(buf, "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" "%%%%%%%%%%%%%%%"); - rc = curl_msnprintf(buf, sizeof(buf), "%2 AA %d %K", 500, 501, 502); + (void)curl_msnprintf(buf, sizeof(buf), "%2 AA %d %K", 500, 501, 502); errors += string_check(buf, "%2 AA 500 %K"); - rc = curl_msnprintf(buf, sizeof(buf), "%2 %d %K", 500, 501, 502); + (void)curl_msnprintf(buf, sizeof(buf), "%2 %d %K", 500, 501, 502); errors += string_check(buf, "%2 500 %K"); /* MAX_PARAMETERS is 128, try exact 128! */ diff --git a/tests/libtest/lib568.c b/tests/libtest/lib568.c index ae29c06415..e5e619c025 100644 --- a/tests/libtest/lib568.c +++ b/tests/libtest/lib568.c @@ -79,12 +79,17 @@ CURLcode test(char *URL) stream_uri = NULL; sdp = open(libtest_arg2, O_RDONLY); + if(sdp == -1) { + fprintf(stderr, "can't open %s\n", libtest_arg2); + res = TEST_ERR_MAJOR_BAD; + goto test_cleanup; + } fstat(sdp, &file_info); close(sdp); sdpf = fopen(libtest_arg2, "rb"); if(!sdpf) { - fprintf(stderr, "can't open %s\n", libtest_arg2); + fprintf(stderr, "can't fopen %s\n", libtest_arg2); res = TEST_ERR_MAJOR_BAD; goto test_cleanup; } diff --git a/tests/libtest/lib569.c b/tests/libtest/lib569.c index 847116a34a..3f735ae79a 100644 --- a/tests/libtest/lib569.c +++ b/tests/libtest/lib569.c @@ -110,6 +110,8 @@ CURLcode test(char *URL) test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_TEARDOWN); res = curl_easy_perform(curl); + if(res) + goto test_cleanup; /* Clear for the next go-round */ test_setopt(curl, CURLOPT_RTSP_SESSION_ID, NULL); diff --git a/tests/libtest/lib570.c b/tests/libtest/lib570.c index 3d15e9bcf8..49c768abd3 100644 --- a/tests/libtest/lib570.c +++ b/tests/libtest/lib570.c @@ -108,7 +108,7 @@ CURLcode test(char *URL) } else { fprintf(stderr, "Failed to detect a Session ID mismatch"); - res = (CURLcode)1; + res = TEST_ERR_FAILURE; } test_cleanup: diff --git a/tests/libtest/lib572.c b/tests/libtest/lib572.c index f28b741b0b..86a0f7b331 100644 --- a/tests/libtest/lib572.c +++ b/tests/libtest/lib572.c @@ -98,12 +98,17 @@ CURLcode test(char *URL) /* PUT style GET_PARAMETERS */ params = open(libtest_arg2, O_RDONLY); + if(params == -1) { + fprintf(stderr, "can't open %s\n", libtest_arg2); + res = TEST_ERR_MAJOR_BAD; + goto test_cleanup; + } fstat(params, &file_info); close(params); paramsf = fopen(libtest_arg2, "rb"); if(!paramsf) { - fprintf(stderr, "can't open %s\n", libtest_arg2); + fprintf(stderr, "can't fopen %s\n", libtest_arg2); res = TEST_ERR_MAJOR_BAD; goto test_cleanup; } diff --git a/tests/libtest/lib579.c b/tests/libtest/lib579.c index 9b1591fad1..21904c1e8b 100644 --- a/tests/libtest/lib579.c +++ b/tests/libtest/lib579.c @@ -45,9 +45,13 @@ static size_t last_ul_total = 0; static void progress_final_report(void) { FILE *moo = fopen(libtest_arg2, "ab"); - fprintf(moo, "Progress: end UL %zu/%zu\n", last_ul, last_ul_total); + fprintf(moo ? moo : stderr, "Progress: end UL %zu/%zu\n", + last_ul, last_ul_total); + if(moo) + fclose(moo); + else + fprintf(stderr, "Progress: end UL, can't open %s\n", libtest_arg2); started = FALSE; - fclose(moo); } static int progress_callback(void *clientp, double dltotal, double dlnow, @@ -65,9 +69,13 @@ static int progress_callback(void *clientp, double dltotal, double dlnow, last_ul_total = (size_t)ultotal; if(!started) { FILE *moo = fopen(libtest_arg2, "ab"); - fprintf(moo, "Progress: start UL %zu/%zu\n", last_ul, last_ul_total); + fprintf(moo ? moo : stderr, "Progress: start UL %zu/%zu\n", + last_ul, last_ul_total); + if(moo) + fclose(moo); + else + fprintf(stderr, "Progress: start UL, can't open %s\n", libtest_arg2); started = TRUE; - fclose(moo); } return 0; diff --git a/tests/libtest/lib590.c b/tests/libtest/lib590.c index 8fc483e483..f07bc9a0f5 100644 --- a/tests/libtest/lib590.c +++ b/tests/libtest/lib590.c @@ -68,6 +68,8 @@ CURLcode test(char *URL) test_setopt(curl, CURLOPT_PROXYUSERPWD, "me:password"); res = curl_easy_perform(curl); + if(res) + goto test_cleanup; res = curl_easy_getinfo(curl, CURLINFO_PROXYAUTH_USED, &usedauth); if(CURLAUTH_NTLM != usedauth) { diff --git a/tests/libtest/lib643.c b/tests/libtest/lib643.c index bd7f5e0f8c..d25f3ec6e0 100644 --- a/tests/libtest/lib643.c +++ b/tests/libtest/lib643.c @@ -36,12 +36,14 @@ struct WriteThis { static size_t read_callback(char *ptr, size_t size, size_t nmemb, void *userp) { struct WriteThis *pooh = (struct WriteThis *)userp; - int eof = !*pooh->readptr; + int eof; if(size*nmemb < 1) return 0; -#ifndef LIB645 +#ifdef LIB645 + eof = !*pooh->readptr; +#else eof = pooh->sizeleft <= 0; if(!eof) pooh->sizeleft--; @@ -242,7 +244,7 @@ static CURLcode cyclic_add(void) curl_easy_cleanup(easy); if(a1 != CURLE_BAD_FUNCTION_ARGUMENT) /* that should have failed */ - return (CURLcode)1; + return TEST_ERR_FAILURE; return CURLE_OK; } diff --git a/tests/libtest/lib654.c b/tests/libtest/lib654.c index 66ec29d17c..93c47612d7 100644 --- a/tests/libtest/lib654.c +++ b/tests/libtest/lib654.c @@ -44,7 +44,7 @@ static void free_callback(void *userp) static size_t read_callback(char *ptr, size_t size, size_t nmemb, void *userp) { struct WriteThis *pooh = (struct WriteThis *)userp; - int eof = !*pooh->readptr; + int eof; if(size*nmemb < 1) return 0; diff --git a/tests/libtest/lib667.c b/tests/libtest/lib667.c index d190601464..3d02595ba8 100644 --- a/tests/libtest/lib667.c +++ b/tests/libtest/lib667.c @@ -36,7 +36,7 @@ struct WriteThis { static size_t read_callback(char *ptr, size_t size, size_t nmemb, void *userp) { struct WriteThis *pooh = (struct WriteThis *)userp; - int eof = !*pooh->readptr; + int eof; if(size*nmemb < 1) return 0; diff --git a/tests/libtest/lib694.c b/tests/libtest/lib694.c index b1791e4dd7..6057eaeafb 100644 --- a/tests/libtest/lib694.c +++ b/tests/libtest/lib694.c @@ -54,8 +54,12 @@ CURLcode test(char *URL) do { res = curl_easy_perform(curl); + if(res) + goto test_cleanup; res = curl_easy_getinfo(curl, CURLINFO_HTTPAUTH_USED, &usedauth); + if(res) + goto test_cleanup; if(CURLAUTH_NTLM != usedauth) { printf("CURLINFO_HTTPAUTH_USED did not say NTLM\n"); } diff --git a/tests/libtest/mk-lib1521.pl b/tests/libtest/mk-lib1521.pl index 273dfc29ec..82970d1d4b 100755 --- a/tests/libtest/mk-lib1521.pl +++ b/tests/libtest/mk-lib1521.pl @@ -594,6 +594,7 @@ MOO print $fh <