2
0
mirror of https://github.com/curl/curl.git synced 2025-04-24 16:40:32 +08:00

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  (possibly)

- extend two existing `NOLINT` comments with details.

Follow-up to fabfa8e4024473035b3e5c3c30c330be726d9bb4 

Closes 
This commit is contained in:
Viktor Szakats 2025-03-18 00:39:57 +01:00
parent efa65b24ae
commit 9465327084
No known key found for this signature in database
GPG Key ID: B5ABD165E2AEF201
52 changed files with 257 additions and 179 deletions

@ -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")

@ -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`

@ -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

@ -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);

@ -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;

@ -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. */

@ -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;
}

@ -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")

@ -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)

@ -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;
}
}

@ -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

@ -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);

@ -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;
}

@ -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));
}

@ -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);

@ -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 */
}

@ -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;
}

@ -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)

@ -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 */

@ -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;
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);
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;
}

@ -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;
}

@ -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;
}

@ -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");

@ -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;

@ -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! */
}

@ -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) */

@ -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;
}

@ -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);

@ -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 */

@ -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! */

@ -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;
}

@ -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);

@ -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:

@ -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;
}

@ -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;

@ -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) {

@ -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;
}

@ -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;

@ -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;

@ -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");
}

@ -594,6 +594,7 @@ MOO
print $fh <<FOOTER
)
/* NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange) */
curl_easy_setopt(curl, (CURLoption)1, 0);
res = CURLE_OK;
test_cleanup:

@ -96,18 +96,18 @@ extern int unitfail;
** For portability reasons TEST_ERR_* values should be less than 127.
*/
#define TEST_ERR_MAJOR_BAD (CURLcode) 126
#define TEST_ERR_RUNS_FOREVER (CURLcode) 125
#define TEST_ERR_EASY_INIT (CURLcode) 124
#define TEST_ERR_MULTI (CURLcode) 123
#define TEST_ERR_NUM_HANDLES (CURLcode) 122
#define TEST_ERR_SELECT (CURLcode) 121
#define TEST_ERR_SUCCESS (CURLcode) 120
#define TEST_ERR_FAILURE (CURLcode) 119
#define TEST_ERR_USAGE (CURLcode) 118
#define TEST_ERR_FOPEN (CURLcode) 117
#define TEST_ERR_FSTAT (CURLcode) 116
#define TEST_ERR_BAD_TIMEOUT (CURLcode) 115
#define TEST_ERR_MAJOR_BAD CURLE_RESERVED126
#define TEST_ERR_RUNS_FOREVER CURLE_RESERVED125
#define TEST_ERR_EASY_INIT CURLE_RESERVED124
#define TEST_ERR_MULTI CURLE_RESERVED123
#define TEST_ERR_NUM_HANDLES CURLE_RESERVED122
#define TEST_ERR_SELECT CURLE_RESERVED121
#define TEST_ERR_SUCCESS CURLE_RESERVED120
#define TEST_ERR_FAILURE CURLE_RESERVED119
#define TEST_ERR_USAGE CURLE_RESERVED118
#define TEST_ERR_FOPEN CURLE_RESERVED117
#define TEST_ERR_FSTAT CURLE_RESERVED116
#define TEST_ERR_BAD_TIMEOUT CURLE_RESERVED115
/*
** Macros for test source code readability/maintainability.
@ -507,7 +507,7 @@ extern int unitfail;
{ \
(void)URL; \
fprintf(stderr, "Missing support\n"); \
return (CURLcode)1; \
return CURLE_UNSUPPORTED_PROTOCOL; \
}
#endif
@ -525,6 +525,6 @@ extern CURLcode test(char *URL); /* the actual test function provided by each
{ \
(void)URL; \
fprintf(stderr, "Missing support\n"); \
return (CURLcode)1; \
return CURLE_UNSUPPORTED_PROTOCOL; \
}
#endif

@ -584,14 +584,14 @@ static void rtspd_storerequest(char *reqbuf, size_t totalsize)
writeleft = totalsize;
do {
written = fwrite(&reqbuf[totalsize-writeleft],
1, writeleft, dump);
written = fwrite(&reqbuf[totalsize-writeleft], 1, writeleft, dump);
if(got_exit_signal)
goto storerequest_cleanup;
if(written > 0)
writeleft -= written;
error = errno;
/* !checksrc! disable ERRNOVAR 1 */
} while((writeleft > 0) && ((error = errno) == EINTR));
} while((writeleft > 0) && (error == EINTR));
if(writeleft == 0)
logmsg("Wrote request (%zu bytes) input to %s", totalsize, dumpfile);

@ -772,14 +772,14 @@ static void sws_storerequest(const char *reqbuf, size_t totalsize)
writeleft = totalsize;
do {
written = fwrite(&reqbuf[totalsize-writeleft],
1, writeleft, dump);
written = fwrite(&reqbuf[totalsize-writeleft], 1, writeleft, dump);
if(got_exit_signal)
goto storerequest_cleanup;
if(written > 0)
writeleft -= written;
error = errno;
/* !checksrc! disable ERRNOVAR 1 */
} while((writeleft > 0) && ((error = errno) == EINTR));
} while((writeleft > 0) && (error == EINTR));
if(writeleft == 0)
logmsg("Wrote request (%zu bytes) input to %s", totalsize, dumpfile);

@ -176,7 +176,7 @@ for my $e (sort @syms) {
# last entry in many enum series.
#
if($e =~ /(OBSOLETE|^CURL_EXTERN|^CURLINC_|_LAST\z|_LASTENTRY\z|^CURL_TEMP_)/) {
if($e =~ /(OBSOLETE|CURLE_RESERVED|^CURL_EXTERN|^CURLINC_|_LAST\z|_LASTENTRY\z|^CURL_TEMP_)/) {
$ignored++;
next;
}

@ -49,7 +49,7 @@ sub scanheader {
$line++;
if($_ =~ /^ (CURL(E|UE|SHE|HE|M)_[A-Z0-9_]*)/) {
my ($name)=($1);
if(($name !~ /OBSOLETE/) && ($name !~ /_LAST\z/)) {
if(($name !~ /(OBSOLETE|CURLE_RESERVED)/) && ($name !~ /_LAST\z/)) {
push @hnames, $name;
if($wherefrom{$name}) {
print STDERR "double: $name\n";

@ -60,7 +60,7 @@ UNITTEST_START
struct Curl_llist_node *element_next;
struct Curl_llist_node *element_prev;
struct Curl_llist_node *to_remove;
size_t llist_size = Curl_llist_count(&llist);
size_t llist_size;
/**
* testing llist_init

@ -58,11 +58,14 @@ static void test_parse(
fail_unless(!!exp_options == !!options, "options expectation failed");
if(!unitfail) {
fail_unless(!exp_username || strcmp(userstr, exp_username) == 0,
fail_unless(!userstr || !exp_username ||
strcmp(userstr, exp_username) == 0,
"userstr should be equal to exp_username");
fail_unless(!exp_password || strcmp(passwdstr, exp_password) == 0,
fail_unless(!passwdstr || !exp_password ||
strcmp(passwdstr, exp_password) == 0,
"passwdstr should be equal to exp_password");
fail_unless(!exp_options || strcmp(options, exp_options) == 0,
fail_unless(!options || !exp_options ||
strcmp(options, exp_options) == 0,
"options should be equal to exp_options");
}

@ -88,7 +88,7 @@ UNITTEST_START
result = Curl_altsvc_parse(curl, asi,
"h2=\"example.net:443\"; ma=\"180\";\r\n",
ALPN_h2, "example.net", 80);
fail_if(result, "Curl_altsvc_parse(4) failed!");
fail_if(result, "Curl_altsvc_parse(5) failed!");
fail_unless(Curl_llist_count(&asi->list) == 10, "wrong number of entries");
result =
@ -96,34 +96,38 @@ UNITTEST_START
"h2=\":443\", h3=\":443\"; "
"persist = \"1\"; ma = 120;\r\n",
ALPN_h1, "curl.se", 80);
fail_if(result, "Curl_altsvc_parse(5) failed!");
fail_if(result, "Curl_altsvc_parse(6) failed!");
fail_unless(Curl_llist_count(&asi->list) == 12, "wrong number of entries");
/* clear that one again and decrease the counter */
result = Curl_altsvc_parse(curl, asi, "clear;\r\n",
ALPN_h1, "curl.se", 80);
fail_if(result, "Curl_altsvc_parse(6) failed!");
fail_if(result, "Curl_altsvc_parse(7) failed!");
fail_unless(Curl_llist_count(&asi->list) == 10, "wrong number of entries");
/* only a non-existing alpn */
result = Curl_altsvc_parse(curl, asi,
"h6=\"example.net:443\"; ma=\"180\";\r\n",
ALPN_h2, "5.example.net", 80);
fail_if(result, "Curl_altsvc_parse(8) failed!");
/* missing quote in alpn host */
result = Curl_altsvc_parse(curl, asi,
"h2=\"example.net:443,; ma=\"180\";\r\n",
ALPN_h2, "6.example.net", 80);
fail_if(result, "Curl_altsvc_parse(9) failed!");
/* missing port in host name */
result = Curl_altsvc_parse(curl, asi,
"h2=\"example.net\"; ma=\"180\";\r\n",
ALPN_h2, "7.example.net", 80);
fail_if(result, "Curl_altsvc_parse(10) failed!");
/* illegal port in host name */
result = Curl_altsvc_parse(curl, asi,
"h2=\"example.net:70000\"; ma=\"180\";\r\n",
ALPN_h2, "8.example.net", 80);
fail_if(result, "Curl_altsvc_parse(11) failed!");
Curl_altsvc_save(curl, asi, outname);

@ -100,8 +100,10 @@ UNITTEST_START
buffer = (const char *)Curl_bufref_ptr(&bufref);
fail_unless(buffer, "Allocated pointer is NULL");
fail_unless(bufref.len == 3, "Wrong data size stored");
fail_unless(!buffer[3], "Duplicated data should have been truncated");
fail_unless(!strcmp(buffer, "166"), "Bad duplicated data");
if(buffer) {
fail_unless(!buffer[3], "Duplicated data should have been truncated");
fail_unless(!strcmp(buffer, "166"), "Bad duplicated data");
}
/**
* testing Curl_bufref_free

@ -66,11 +66,11 @@ static void test_parse(
fail_unless(!!exp_host == !!host, "host expectation failed");
if(!unitfail) {
fail_unless(!exp_dev || strcmp(dev, exp_dev) == 0,
fail_unless(!dev || !exp_dev || strcmp(dev, exp_dev) == 0,
"dev should be equal to exp_dev");
fail_unless(!exp_iface || strcmp(iface, exp_iface) == 0,
fail_unless(!iface || !exp_iface || strcmp(iface, exp_iface) == 0,
"iface should be equal to exp_iface");
fail_unless(!exp_host || strcmp(host, exp_host) == 0,
fail_unless(!host || !exp_host || strcmp(host, exp_host) == 0,
"host should be equal to exp_host");
}

@ -108,11 +108,11 @@ UNITTEST_START
case 0:
rc = Curl_get_line(&buf, fp);
line = Curl_dyn_ptr(&buf);
fail_unless(line && !strcmp("LINE1\n", line),
fail_unless(rc && line && !strcmp("LINE1\n", line),
"First line failed (1)");
rc = Curl_get_line(&buf, fp);
line = Curl_dyn_ptr(&buf);
fail_unless(line && !strcmp("LINE2 NEWLINE\n", line),
fail_unless(rc && line && !strcmp("LINE2 NEWLINE\n", line),
"Second line failed (1)");
rc = Curl_get_line(&buf, fp);
abort_unless(!Curl_dyn_len(&buf), "Missed EOF (1)");
@ -120,11 +120,11 @@ UNITTEST_START
case 1:
rc = Curl_get_line(&buf, fp);
line = Curl_dyn_ptr(&buf);
fail_unless(line && !strcmp("LINE1\n", line),
fail_unless(rc && line && !strcmp("LINE1\n", line),
"First line failed (2)");
rc = Curl_get_line(&buf, fp);
line = Curl_dyn_ptr(&buf);
fail_unless(line && !strcmp("LINE2 NONEWLINE\n", line),
fail_unless(rc && line && !strcmp("LINE2 NONEWLINE\n", line),
"Second line failed (2)");
rc = Curl_get_line(&buf, fp);
abort_unless(!Curl_dyn_len(&buf), "Missed EOF (2)");
@ -132,7 +132,7 @@ UNITTEST_START
case 2:
rc = Curl_get_line(&buf, fp);
line = Curl_dyn_ptr(&buf);
fail_unless(line && !strcmp("LINE1\n", line),
fail_unless(rc && line && !strcmp("LINE1\n", line),
"First line failed (3)");
rc = Curl_get_line(&buf, fp);
fail_unless(!Curl_dyn_len(&buf),
@ -141,7 +141,7 @@ UNITTEST_START
case 3:
rc = Curl_get_line(&buf, fp);
line = Curl_dyn_ptr(&buf);
fail_unless(line && !strcmp("LINE1\n", line),
fail_unless(rc && line && !strcmp("LINE1\n", line),
"First line failed (4)");
rc = Curl_get_line(&buf, fp);
fail_unless(!Curl_dyn_len(&buf),
@ -150,7 +150,7 @@ UNITTEST_START
case 4:
rc = Curl_get_line(&buf, fp);
line = Curl_dyn_ptr(&buf);
fail_unless(line && !strcmp("LINE1\n", line),
fail_unless(rc && line && !strcmp("LINE1\n", line),
"First line failed (5)");
rc = Curl_get_line(&buf, fp);
fail_unless(!Curl_dyn_len(&buf),
@ -159,7 +159,7 @@ UNITTEST_START
case 5:
rc = Curl_get_line(&buf, fp);
line = Curl_dyn_ptr(&buf);
fail_unless(line && !strcmp("LINE1\x1aTEST\n", line),
fail_unless(rc && line && !strcmp("LINE1\x1aTEST\n", line),
"Missed/Misinterpreted ^Z (6)");
rc = Curl_get_line(&buf, fp);
abort_unless(!Curl_dyn_len(&buf), "Missed EOF (6)");