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")
- `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`
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
/* 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);
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;
/* 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. */
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;
}
# 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")
if(!(expr)) { \
fprintf(stderr, "%s:%d Assertion '%s' failed: %s\n", \
__FILE__, __LINE__, #expr, msg); \
- return (CURLcode)1; \
+ return TEST_ERR_FAILURE; \
} \
} while(0)
fprintf(stderr, "pong = %ld\n", e);
if(e > MAX_BLOCKED_TIME_MS) {
- res = (CURLcode) 100;
+ res = CURLE_TOO_LARGE;
break;
}
}
#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
/* 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);
}
-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;
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");
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;
}
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;
}
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;
}
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;
}
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);
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));
}
{
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);
return CURLUPART_FRAGMENT;
if(!strcmp("zoneid", part))
return CURLUPART_ZONEID;
+ /* NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange) */
return (CURLUPart)9999; /* bad input => bad output */
}
{
CURL *curl = NULL;
CURLcode res = CURLE_OK;
- CURLcode result = CURLE_OK;
curl_version_info_data *curlinfo;
const char *const *proto;
int n;
/* 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;
}
}
curl_easy_cleanup(curl);
curl_global_cleanup();
- return result;
+ return res;
}
cm = curl_multi_init();
if(!cm) {
curl_global_cleanup();
- return (CURLcode)1;
+ return TEST_ERR_MULTI;
}
sh = curl_share_init();
if(!sh)
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 */
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;
}
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;
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
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;
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)
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++) {
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;
}
}
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;
}
}
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;
}
struct Ctx {
const char *URL;
CURLSH *share;
- int result;
+ CURLcode result;
int thread_id;
struct curl_slist *contents;
};
}
test_cleanup:
- ctx->result = (int)res;
+ ctx->result = res;
return 0;
}
CURLcode test(char *URL)
{
- int res = 0;
+ CURLcode res = CURLE_OK;
int i;
CURLSH* share;
struct Ctx ctx[THREAD_SIZE];
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;
}
if(share)
curl_share_cleanup(share);
curl_global_cleanup();
- return (CURLcode)res;
+ return res;
}
curl_easy_cleanup(curl);
- res = CURLE_OK;
-
/* start treads */
for(i = 1; i <= THREADS; i++) {
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");
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;
/* 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! */
}
/* 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! */
}
{
(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) */
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;
}
start_test_timing();
if(test_argc < 4)
- return (CURLcode)99;
+ return TEST_ERR_MAJOR_BAD;
msnprintf(buffer, sizeof(buffer), "Host: %s", HOST);
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 */
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! */
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;
}
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);
}
else {
fprintf(stderr, "Failed to detect a Session ID mismatch");
- res = (CURLcode)1;
+ res = TEST_ERR_FAILURE;
}
test_cleanup:
/* 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;
}
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,
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;
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) {
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--;
curl_easy_cleanup(easy);
if(a1 != CURLE_BAD_FUNCTION_ARGUMENT)
/* that should have failed */
- return (CURLcode)1;
+ return TEST_ERR_FAILURE;
return CURLE_OK;
}
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;
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;
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");
}
print $fh <<FOOTER
)
+ /* NOLINTNEXTLINE(clang-analyzer-optin.core.EnumCastOutOfRange) */
curl_easy_setopt(curl, (CURLoption)1, 0);
res = CURLE_OK;
test_cleanup:
** 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.
{ \
(void)URL; \
fprintf(stderr, "Missing support\n"); \
- return (CURLcode)1; \
+ return CURLE_UNSUPPORTED_PROTOCOL; \
}
#endif
{ \
(void)URL; \
fprintf(stderr, "Missing support\n"); \
- return (CURLcode)1; \
+ return CURLE_UNSUPPORTED_PROTOCOL; \
}
#endif
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);
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);
# 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;
}
$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";
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
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");
}
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 =
"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);
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
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");
}
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)");
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)");
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),
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),
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),
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)");