checksrc: reduce directory-specific exceptions

By making them defaults, then fixing and/or reshuffling remaining
exceptions as necessary.

- checksrc: ban by default: `snprintf`, `vsnprintf`, `sscanf`, `strtol`.
- examples: replace `strtol` with `atoi` to avoid a checksrc exception.
- tests/libtest: replace `strtol` with `atol`.
- tests/server: replace most `strtol` with `atol`.
- tests/server: replace most `strtoul` with `atol`/`atoi`.
- tests/server: drop no longer used `util_ultous`.
- fix typo in checksrc rules: `vsnprint` -> `vsnprintf`.
- update local exceptions.

Also:
- examples: ban curl printf functions. They're discouraged in user code.
- examples: replace curl printf with system printf.
  Add `snprintf` workaround for <VS2015.
- examples/synctime: fix `-Wfloat-equal`.
- examples/synctime: exclude for non-Windows and non-UWP Windows.
- examples/synctime: build by default.

Closes #18823
This commit is contained in:
Viktor Szakats 2025-10-02 21:33:48 +02:00
parent fff36a360e
commit 45438c8d6f
No known key found for this signature in database
GPG key ID: B5ABD165E2AEF201
36 changed files with 124 additions and 142 deletions

View file

@ -4,4 +4,14 @@ allowfunc fopen
allowfunc gmtime
allowfunc localtime
allowfunc open
allowfunc snprintf
allowfunc socket
allowfunc sscanf
banfunc curl_maprintf
banfunc curl_mfprintf
banfunc curl_mprintf
banfunc curl_msnprintf
banfunc curl_mvaprintf
banfunc curl_mvfprintf
banfunc curl_mvprintf
banfunc curl_mvsnprintf

View file

@ -132,6 +132,7 @@ check_PROGRAMS = \
smtp-tls \
smtp-vrfy \
sslbackend \
synctime \
unixsocket \
url2file \
urlapi \
@ -155,7 +156,6 @@ COMPLICATED_EXAMPLES = \
multithread.c \
sessioninfo.c \
smooth-gtk-thread.c \
synctime.c \
threaded-ssl.c \
usercertinmem.c \
version-check.pl \

View file

@ -100,7 +100,7 @@ int main(int argc, char *argv[])
case 'm':
case 'M':
if(argv[0][2] == '=') {
long m = strtol((*argv) + 3, NULL, 10);
int m = atoi((*argv) + 3);
switch(m) {
case 1:
url = URL_1M;

View file

@ -34,6 +34,10 @@
#include <curl/curl.h>
#include <curl/mprintf.h>
#if defined(_MSC_VER) && (_MSC_VER < 1900)
#define snprintf _snprintf
#endif
static int print_cookies(CURL *curl)
{
CURLcode res;
@ -93,10 +97,10 @@ main(void)
printf("-----------------------------------------------\n"
"Setting a cookie \"PREF\" via cookie interface:\n");
/* Netscape format cookie */
curl_msnprintf(nline, sizeof(nline), "%s\t%s\t%s\t%s\t%.0f\t%s\t%s",
".example.com", "TRUE", "/", "FALSE",
difftime(time(NULL) + 31337, (time_t)0),
"PREF", "hello example, i like you!");
snprintf(nline, sizeof(nline), "%s\t%s\t%s\t%s\t%.0f\t%s\t%s",
".example.com", "TRUE", "/", "FALSE",
difftime(time(NULL) + 31337, (time_t)0),
"PREF", "hello example, I like you!");
res = curl_easy_setopt(curl, CURLOPT_COOKIELIST, nline);
if(res != CURLE_OK) {
fprintf(stderr, "Curl curl_easy_setopt failed: %s\n",
@ -109,7 +113,7 @@ main(void)
modified, likely not what you intended. For more information refer to
the CURLOPT_COOKIELIST documentation.
*/
curl_msnprintf(nline, sizeof(nline),
snprintf(nline, sizeof(nline),
"Set-Cookie: OLD_PREF=3d141414bf4209321; "
"expires=Sun, 17-Jan-2038 19:14:07 GMT; path=/; domain=.example.com");
res = curl_easy_setopt(curl, CURLOPT_COOKIELIST, nline);

View file

@ -38,6 +38,10 @@
#include <curl/curl.h>
#include <curl/mprintf.h>
#if defined(_MSC_VER) && (_MSC_VER < 1900)
#define snprintf _snprintf
#endif
#ifndef CURLPIPE_MULTIPLEX
/* This little trick makes sure that we do not enable pipelining for libcurls
old enough to not have this symbol. It is _not_ defined to zero in a recent
@ -149,7 +153,7 @@ static int setup(struct transfer *t, int num)
hnd = t->easy = curl_easy_init();
curl_msnprintf(filename, 128, "dl-%d", num);
snprintf(filename, sizeof(filename), "dl-%d", num);
t->out = fopen(filename, "wb");
if(!t->out) {

View file

@ -33,6 +33,10 @@
#include <curl/curl.h>
#include <curl/mprintf.h>
#if defined(_MSC_VER) && (_MSC_VER < 1900)
#define snprintf _snprintf
#endif
#ifndef CURLPIPE_MULTIPLEX
#error "too old libcurl, cannot do HTTP/2 server push!"
#endif
@ -173,7 +177,7 @@ static int server_push_callback(CURL *parent,
(void)parent;
curl_msnprintf(filename, 128, "push%u", count++);
snprintf(filename, sizeof(filename), "push%u", count++);
/* here's a new stream, save it in a new file for each new push */
out = fopen(filename, "wb");

View file

@ -40,6 +40,8 @@
#ifndef _MSC_VER
#include <sys/time.h>
#include <unistd.h>
#elif (_MSC_VER < 1900)
#define snprintf _snprintf
#endif
#ifdef _WIN32
@ -162,8 +164,8 @@ int my_trace(CURL *handle, curl_infotype type,
}
secs = epoch_offset + tv.tv_sec;
now = localtime(&secs); /* not thread safe but we do not care */
curl_msnprintf(timebuf, sizeof(timebuf), "%02d:%02d:%02d.%06ld",
now->tm_hour, now->tm_min, now->tm_sec, (long)tv.tv_usec);
snprintf(timebuf, sizeof(timebuf), "%02d:%02d:%02d.%06ld",
now->tm_hour, now->tm_min, now->tm_sec, (long)tv.tv_usec);
switch(type) {
case CURLINFO_TEXT:
@ -215,7 +217,7 @@ static int setup(struct input *i, int num, const char *upload)
hnd = i->hnd = NULL;
i->num = num;
curl_msnprintf(filename, 128, "dl-%d", num);
snprintf(filename, sizeof(filename), "dl-%d", num);
out = fopen(filename, "wb");
if(!out) {
fprintf(stderr, "error: could not open file %s for writing: %s\n", upload,
@ -223,7 +225,7 @@ static int setup(struct input *i, int num, const char *upload)
return 1;
}
curl_msnprintf(url, 256, "https://localhost:8443/upload-%d", num);
snprintf(url, sizeof(url), "https://localhost:8443/upload-%d", num);
i->in = fopen(upload, "rb");
if(!i->in) {

View file

@ -72,15 +72,32 @@
*/
#include <stdio.h>
#include <time.h>
#include <curl/curl.h>
#ifdef _WIN32
#include <windows.h>
#ifndef _WIN32
int main(void) { printf("Platform not supported.\n"); return 1; }
#else
#error "This example requires Windows."
#if (defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0602)) || \
defined(WINAPI_FAMILY)
# include <winapifamily.h>
# if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) && \
!WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
# define CURL_WINDOWS_UWP
# endif
#endif
#ifdef CURL_WINDOWS_UWP
int main(void) { printf("Platform not supported.\n"); return 1; }
#else
#include <windows.h>
#include <time.h>
#include <curl/curl.h>
#if defined(_MSC_VER) && (_MSC_VER < 1900)
#define snprintf _snprintf
#endif
#define MAX_STRING 256
#define MAX_STRING1 MAX_STRING + 1
@ -139,7 +156,7 @@ static size_t SyncTime_CURL_WriteHeader(void *ptr, size_t size, size_t nmemb,
*TmpStr1 = 0;
*TmpStr2 = 0;
if(strlen((char *)(ptr)) > 50) /* Can prevent buffer overflow to
TmpStr1 & 2? */
TmpStr1 & 2? */
AutoSyncTime = 0;
else {
int RetVal = sscanf((char *)(ptr), "Date: %25s %hu %s %hu %hu:%hu:%hu",
@ -305,7 +322,7 @@ int main(int argc, char *argv[])
tzonediffFloat = difftime(tt_local, tt_gmt);
tzonediffWord = (int)(tzonediffFloat/3600.0);
if((double)(tzonediffWord * 3600) == tzonediffFloat)
if(tzonediffWord == (int)(tzonediffFloat/3600.0))
snprintf(tzoneBuf, sizeof(tzoneBuf), "%+03d'00'", tzonediffWord);
else
snprintf(tzoneBuf, sizeof(tzoneBuf), "%+03d'30'", tzonediffWord);
@ -358,3 +375,5 @@ int main(int argc, char *argv[])
}
return RetValue;
}
#endif /* CURL_WINDOWS_UWP */
#endif /* _WIN32 */

View file

@ -362,6 +362,6 @@ This is the full list of functions generally banned.
strtok_r
strtol
strtoul
vsnprint
vsnprintf
vsprintf
wcsdup

View file

@ -1,5 +1 @@
banfunc snprintf
banfunc sscanf
banfunc strerror
banfunc strtol
banfunc vsnprint

View file

@ -1,5 +1 @@
banfunc snprintf
banfunc sscanf
banfunc strerror
banfunc strtol
banfunc vsnprint

View file

@ -1,5 +1 @@
banfunc snprintf
banfunc sscanf
banfunc strerror
banfunc strtol
banfunc vsnprint

View file

@ -1,5 +1 @@
banfunc snprintf
banfunc sscanf
banfunc strerror
banfunc strtol
banfunc vsnprint

View file

@ -1,5 +1 @@
banfunc snprintf
banfunc sscanf
banfunc strerror
banfunc strtol
banfunc vsnprint

View file

@ -1,5 +1 @@
banfunc snprintf
banfunc sscanf
banfunc strerror
banfunc strtol
banfunc vsnprint

View file

@ -53,11 +53,15 @@ my %banfunc = (
"gets" => 1,
"strtok" => 1,
"sprintf" => 1,
"snprintf" => 1,
"vsprintf" => 1,
"vsnprintf" => 1,
"sscanf" => 1,
"strcat" => 1,
"strncat" => 1,
"strncpy" => 1,
"strtok_r" => 1,
"strtol" => 1,
"strtoul" => 1,
"_mbscat" => 1,
"_mbsncat" => 1,

View file

@ -1,5 +1 @@
enable STDERR
banfunc snprintf
banfunc sscanf
banfunc strtol
banfunc vsnprint

View file

@ -317,32 +317,32 @@ static CURLcode test_cli_hx_download(const char *URL)
forbid_reuse_d = 1;
break;
case 'm':
max_parallel = (size_t)strtol(coptarg, NULL, 10);
max_parallel = (size_t)atol(coptarg);
break;
case 'n':
transfer_count_d = (size_t)strtol(coptarg, NULL, 10);
transfer_count_d = (size_t)atol(coptarg);
break;
case 'x':
fresh_connect = 1;
break;
case 'A':
abort_offset = (size_t)strtol(coptarg, NULL, 10);
abort_offset = (size_t)atol(coptarg);
break;
case 'F':
fail_offset = (size_t)strtol(coptarg, NULL, 10);
fail_offset = (size_t)atol(coptarg);
break;
case 'M':
max_host_conns = (size_t)strtol(coptarg, NULL, 10);
max_host_conns = (size_t)atol(coptarg);
break;
case 'P':
pause_offset = (size_t)strtol(coptarg, NULL, 10);
pause_offset = (size_t)atol(coptarg);
break;
case 'r':
free(resolve);
resolve = strdup(coptarg);
break;
case 'T':
max_total_conns = (size_t)strtol(coptarg, NULL, 10);
max_total_conns = (size_t)atol(coptarg);
break;
case 'V': {
if(!strcmp("http/1.1", coptarg))

View file

@ -257,22 +257,22 @@ static CURLcode test_cli_hx_upload(const char *URL)
announce_length = 1;
break;
case 'm':
max_parallel = (size_t)strtol(coptarg, NULL, 10);
max_parallel = (size_t)atol(coptarg);
break;
case 'n':
transfer_count_u = (size_t)strtol(coptarg, NULL, 10);
transfer_count_u = (size_t)atol(coptarg);
break;
case 'A':
abort_offset = (size_t)strtol(coptarg, NULL, 10);
abort_offset = (size_t)atol(coptarg);
break;
case 'F':
fail_offset = (size_t)strtol(coptarg, NULL, 10);
fail_offset = (size_t)atol(coptarg);
break;
case 'M':
method = coptarg;
break;
case 'P':
pause_offset = (size_t)strtol(coptarg, NULL, 10);
pause_offset = (size_t)atol(coptarg);
break;
case 'r':
resolve = coptarg;
@ -281,7 +281,7 @@ static CURLcode test_cli_hx_upload(const char *URL)
reuse_easy = 1;
break;
case 'S':
send_total = (size_t)strtol(coptarg, NULL, 10);
send_total = (size_t)atol(coptarg);
break;
case 'V': {
if(!strcmp("http/1.1", coptarg))

View file

@ -431,13 +431,13 @@ static CURLcode test_cli_ws_data(const char *URL)
res = CURLE_BAD_FUNCTION_ARGUMENT;
goto cleanup;
case 'c':
count = (size_t)strtol(coptarg, NULL, 10);
count = (size_t)atol(coptarg);
break;
case 'm':
plen_min = (size_t)strtol(coptarg, NULL, 10);
plen_min = (size_t)atol(coptarg);
break;
case 'M':
plen_max = (size_t)strtol(coptarg, NULL, 10);
plen_max = (size_t)atol(coptarg);
break;
default:
test_ws_data_usage("invalid option");

View file

@ -137,9 +137,8 @@ static void memory_tracking_init(void)
/* if CURL_MEMLIMIT is set, this enables fail-on-alloc-number-N feature */
env = getenv("CURL_MEMLIMIT");
if(env) {
char *endptr;
long num = strtol(env, &endptr, 10);
if((endptr != env) && (endptr == env + strlen(env)) && (num > 0))
long num = atol(env);
if(num > 0)
curl_dbg_memlimit(num);
}
}

View file

@ -1198,6 +1198,7 @@ static CURLUcode updateurl(CURLU *u, const char *cmd, unsigned int setflags)
memset(value, 0, sizeof(value)); /* Avoid valgrind false positive. */
memcpy(buf, p, n);
buf[n] = 0;
/* !checksrc! disable BANNEDFUNC 1 */
if(sscanf(buf, "%79[^=]=%79[^,]", part, value) == 2) {
CURLUPart what = part2id(part);
#if 0

View file

@ -39,7 +39,7 @@ static CURLcode test_lib1568(const char *URL)
curl_easy_setopt(hnd, CURLOPT_USERAGENT, "lib1568");
curl_easy_setopt(hnd, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
curl_easy_setopt(hnd, CURLOPT_MAXREDIRS, 50L);
curl_easy_setopt(hnd, CURLOPT_PORT, strtol(libtest_arg2, NULL, 10));
curl_easy_setopt(hnd, CURLOPT_PORT, atol(libtest_arg2));
ret = curl_easy_perform(hnd);

View file

@ -43,7 +43,7 @@ static CURLcode test_lib521(const char *URL)
}
test_setopt(curl, CURLOPT_URL, URL);
test_setopt(curl, CURLOPT_PORT, strtol(libtest_arg2, NULL, 10));
test_setopt(curl, CURLOPT_PORT, atol(libtest_arg2));
test_setopt(curl, CURLOPT_USERPWD, "xxx:yyy");
test_setopt(curl, CURLOPT_VERBOSE, 1L);

View file

@ -55,7 +55,7 @@ static CURLcode test_lib562(const char *URL)
test_setopt(curl, CURLOPT_VERBOSE, 1L);
/* set port number */
test_setopt(curl, CURLOPT_PORT, strtol(libtest_arg2, NULL, 10));
test_setopt(curl, CURLOPT_PORT, atol(libtest_arg2));
/* specify target */
test_setopt(curl, CURLOPT_URL, URL);

View file

@ -71,8 +71,7 @@ static CURLcode test_lib591(const char *URL)
easy_setopt(easy, CURLOPT_FTPPORT, "-");
/* server connection timeout */
easy_setopt(easy, CURLOPT_ACCEPTTIMEOUT_MS,
strtol(libtest_arg2, NULL, 10)*1000);
easy_setopt(easy, CURLOPT_ACCEPTTIMEOUT_MS, atol(libtest_arg2)*1000);
multi_init(multi);

View file

@ -6,5 +6,7 @@ allowfunc getaddrinfo
allowfunc open
allowfunc recv
allowfunc send
allowfunc snprintf
allowfunc socket
allowfunc strtoul
allowfunc sscanf
allowfunc vsnprintf

View file

@ -441,9 +441,7 @@ static int test_dnsd(int argc, char **argv)
else if(!strcmp("--port", argv[arg])) {
arg++;
if(argc > arg) {
char *endptr;
unsigned long ulnum = strtoul(argv[arg], &endptr, 10);
port = util_ultous(ulnum);
port = (unsigned short)atoi(argv[arg]);
arg++;
}
}

View file

@ -148,7 +148,6 @@ extern void restore_signal_handlers(bool keep_sigalrm);
extern int bind_unix_socket(curl_socket_t sock, const char *unix_socket,
struct sockaddr_un *sau);
#endif
extern unsigned short util_ultous(unsigned long ulnum);
extern curl_socket_t sockdaemon(curl_socket_t sock,
unsigned short *listenport,
const char *unix_socket,

View file

@ -782,15 +782,13 @@ static int test_mqttd(int argc, char *argv[])
else if(!strcmp("--port", argv[arg])) {
arg++;
if(argc > arg) {
char *endptr;
unsigned long ulnum = strtoul(argv[arg], &endptr, 10);
if((endptr != argv[arg] + strlen(argv[arg])) ||
((ulnum != 0UL) && ((ulnum < 1025UL) || (ulnum > 65535UL)))) {
int inum = atoi(argv[arg]);
if(inum && ((inum < 1025) || (inum > 65535))) {
fprintf(stderr, "mqttd: invalid --port argument (%s)\n",
argv[arg]);
return 0;
}
server_port = util_ultous(ulnum);
server_port = (unsigned short)inum;
arg++;
}
}

View file

@ -211,7 +211,7 @@ static int rtspd_ProcessRequest(struct rtspd_httprequest *req)
while(*ptr && !ISDIGIT(*ptr))
ptr++;
req->testno = strtol(ptr, &ptr, 10);
req->testno = atol(ptr);
if(req->testno > 10000) {
req->partno = req->testno % 10000;
@ -358,7 +358,7 @@ static int rtspd_ProcessRequest(struct rtspd_httprequest *req)
CONNECT line will be used as test number! */
char *portp = strchr(doc, ':');
if(portp && (*(portp + 1) != '\0') && ISDIGIT(*(portp + 1)))
req->testno = strtol(portp + 1, NULL, 10);
req->testno = atol(portp + 1);
else
req->testno = DOCNUMBER_CONNECT;
}
@ -1045,9 +1045,7 @@ static int test_rtspd(int argc, char *argv[])
else if(!strcmp("--port", argv[arg])) {
arg++;
if(argc > arg) {
char *endptr;
unsigned long ulnum = strtoul(argv[arg], &endptr, 10);
port = util_ultous(ulnum);
port = (unsigned short)atol(argv[arg]);
arg++;
}
}

View file

@ -376,6 +376,7 @@ static bool read_data_block(unsigned char *buffer, ssize_t maxlen,
buffer[5] = '\0';
/* !checksrc! disable BANNEDFUNC 1 */
*buffer_len = (ssize_t)strtol((char *)buffer, NULL, 16);
if(*buffer_len > maxlen) {
logmsg("Buffer size (%zd bytes) too small for data size error "
@ -1278,9 +1279,7 @@ static int test_sockfilt(int argc, char *argv[])
else if(!strcmp("--port", argv[arg])) {
arg++;
if(argc > arg) {
char *endptr;
unsigned long ulnum = strtoul(argv[arg], &endptr, 10);
server_port = util_ultous(ulnum);
server_port = (unsigned short)atol(argv[arg]);
arg++;
}
}
@ -1289,15 +1288,13 @@ static int test_sockfilt(int argc, char *argv[])
doing a passive server-style listening. */
arg++;
if(argc > arg) {
char *endptr;
unsigned long ulnum = strtoul(argv[arg], &endptr, 10);
if((endptr != argv[arg] + strlen(argv[arg])) ||
(ulnum < 1025UL) || (ulnum > 65535UL)) {
int inum = atoi(argv[arg]);
if(inum && ((inum < 1025) || (inum > 65535))) {
fprintf(stderr, "sockfilt: invalid --connect argument (%s)\n",
argv[arg]);
return 0;
}
server_connectport = util_ultous(ulnum);
server_connectport = (unsigned short)inum;
arg++;
}
}

View file

@ -108,7 +108,7 @@ static void socksd_resetdefaults(void)
static unsigned short shortval(char *value)
{
unsigned long num = strtoul(value, NULL, 10);
unsigned long num = (unsigned long)atol(value);
return num & 0xffff;
}
@ -831,9 +831,7 @@ static int test_socksd(int argc, char *argv[])
else if(!strcmp("--port", argv[arg])) {
arg++;
if(argc > arg) {
char *endptr;
unsigned long ulnum = strtoul(argv[arg], &endptr, 10);
server_port = util_ultous(ulnum);
server_port = (unsigned short)atol(argv[arg]);
arg++;
}
}

View file

@ -389,7 +389,7 @@ static int sws_ProcessRequest(struct sws_httprequest *req)
ptr++; /* skip the slash */
req->testno = strtol(ptr, &ptr, 10);
req->testno = atol(ptr);
if(req->testno > 10000) {
req->partno = req->testno % 10000;
@ -430,6 +430,7 @@ static int sws_ProcessRequest(struct sws_httprequest *req)
in the 'part' variable and use as test case number!! */
while(*p && (ISXDIGIT(*p) || (*p == ':') || (*p == '.'))) {
char *endp;
/* !checksrc! disable BANNEDFUNC 1 */
part = strtoul(p, &endp, 16);
if(ISXDIGIT(*p))
p = endp;
@ -449,11 +450,11 @@ static int sws_ProcessRequest(struct sws_httprequest *req)
portp = strchr(doc, ':');
if(portp && (*(portp + 1) != '\0') && ISDIGIT(*(portp + 1))) {
unsigned long ulnum = strtoul(portp + 1, NULL, 10);
if(!ulnum || (ulnum > 65535UL))
int inum = atoi(portp + 1);
if((inum <= 0) || (inum > 65535))
logmsg("Invalid CONNECT port received");
else
req->connect_port = util_ultous(ulnum);
req->connect_port = (unsigned short)inum;
}
logmsg("Port number: %d, test case number: %ld",
@ -490,7 +491,7 @@ static int sws_ProcessRequest(struct sws_httprequest *req)
/* check for a Testno: header with the test case number */
char *testno = strstr(line, "\nTestno: ");
if(testno) {
req->testno = strtol(&testno[9], NULL, 10);
req->testno = atol(&testno[9]);
logmsg("Found test number %ld in Testno: header!", req->testno);
}
else {
@ -516,7 +517,7 @@ static int sws_ProcessRequest(struct sws_httprequest *req)
while(*ptr && !ISDIGIT(*ptr))
ptr++;
req->testno = strtol(ptr, &ptr, 10);
req->testno = atol(ptr);
if(req->testno > 10000) {
req->partno = req->testno % 10000;
@ -2071,15 +2072,13 @@ static int test_sws(int argc, char *argv[])
else if(!strcmp("--port", argv[arg])) {
arg++;
if(argc > arg) {
char *endptr;
unsigned long ulnum = strtoul(argv[arg], &endptr, 10);
if((endptr != argv[arg] + strlen(argv[arg])) ||
(ulnum && ((ulnum < 1025UL) || (ulnum > 65535UL)))) {
int inum = atoi(argv[arg]);
if(inum && ((inum < 1025) || (inum > 65535))) {
fprintf(stderr, "sws: invalid --port argument (%s)\n",
argv[arg]);
return 0;
}
port = util_ultous(ulnum);
port = (unsigned short)inum;
arg++;
}
}
@ -2093,15 +2092,13 @@ static int test_sws(int argc, char *argv[])
else if(!strcmp("--keepalive", argv[arg])) {
arg++;
if(argc > arg) {
char *endptr;
unsigned long ulnum = strtoul(argv[arg], &endptr, 10);
if((endptr != argv[arg] + strlen(argv[arg])) ||
(ulnum && (ulnum > 65535UL))) {
int inum = atoi(argv[arg]);
if(inum && (inum > 65535)) {
fprintf(stderr, "sws: invalid --keepalive argument (%s), must "
"be number of seconds\n", argv[arg]);
return 0;
}
keepalive_secs = util_ultous(ulnum);
keepalive_secs = (unsigned short)inum;
arg++;
}
}

View file

@ -607,9 +607,7 @@ static int test_tftpd(int argc, char **argv)
else if(!strcmp("--port", argv[arg])) {
arg++;
if(argc > arg) {
char *endptr;
unsigned long ulnum = strtoul(argv[arg], &endptr, 10);
port = util_ultous(ulnum);
port = (unsigned short)atol(argv[arg]);
arg++;
}
}
@ -1100,7 +1098,7 @@ static int validate_access(struct testcase *test,
ptr++;
/* get the number */
testno = strtol(ptr, &ptr, 10);
testno = atol(ptr);
if(testno > 10000) {
partno = testno % 10000;

View file

@ -133,7 +133,7 @@ void logmsg(const char *msg, ...)
unsigned char byteval(char *value)
{
unsigned long num = strtoul(value, NULL, 10);
unsigned int num = (unsigned int)atoi(value);
return num & 0xff;
}
@ -748,27 +748,6 @@ int bind_unix_socket(curl_socket_t sock, const char *unix_socket,
}
#endif
/*
** unsigned long to unsigned short
*/
#define CURL_MASK_USHORT ((unsigned short)~0)
#define CURL_MASK_SSHORT (CURL_MASK_USHORT >> 1)
unsigned short util_ultous(unsigned long ulnum)
{
#ifdef __INTEL_COMPILER
# pragma warning(push)
# pragma warning(disable:810) /* conversion may lose significant bits */
#endif
DEBUGASSERT(ulnum <= (unsigned long) CURL_MASK_USHORT);
return (unsigned short)(ulnum & (unsigned long) CURL_MASK_USHORT);
#ifdef __INTEL_COMPILER
# pragma warning(pop)
#endif
}
curl_socket_t sockdaemon(curl_socket_t sock,
unsigned short *listenport,
const char *unix_socket,