tests: fix callback signatures to please UndefinedBehaviorSanitizer

Make test applications use the correct prototypes for callbacks.

Closes #15289
This commit is contained in:
Daniel Stenberg 2024-10-14 13:01:19 +02:00
parent eed3c8f4b7
commit 8403e5a701
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2
17 changed files with 59 additions and 58 deletions

View File

@ -180,7 +180,7 @@ UNITTEST DOHcode doh_req_encode(const char *host,
} }
static size_t static size_t
doh_write_cb(const void *contents, size_t size, size_t nmemb, void *userp) doh_write_cb(char *contents, size_t size, size_t nmemb, void *userp)
{ {
size_t realsize = size * nmemb; size_t realsize = size * nmemb;
struct dynbuf *mem = (struct dynbuf *)userp; struct dynbuf *mem = (struct dynbuf *)userp;

View File

@ -398,9 +398,9 @@ struct events {
* Callback that gets called with a new value when the timeout should be * Callback that gets called with a new value when the timeout should be
* updated. * updated.
*/ */
static int events_timer(struct Curl_multi *multi, /* multi handle */ static int events_timer(CURLM *multi, /* multi handle */
long timeout_ms, /* see above */ long timeout_ms, /* see above */
void *userp) /* private callback pointer */ void *userp) /* private callback pointer */
{ {
struct events *ev = userp; struct events *ev = userp;
(void)multi; (void)multi;
@ -449,7 +449,7 @@ static short socketcb2poll(int pollmask)
* Callback that gets called with information about socket activity to * Callback that gets called with information about socket activity to
* monitor. * monitor.
*/ */
static int events_socket(struct Curl_easy *easy, /* easy handle */ static int events_socket(CURL *easy, /* easy handle */
curl_socket_t s, /* socket */ curl_socket_t s, /* socket */
int what, /* see above */ int what, /* see above */
void *userp, /* private callback void *userp, /* private callback
@ -461,6 +461,7 @@ static int events_socket(struct Curl_easy *easy, /* easy handle */
struct socketmonitor *m; struct socketmonitor *m;
struct socketmonitor *prev = NULL; struct socketmonitor *prev = NULL;
bool found = FALSE; bool found = FALSE;
struct Curl_easy *data = easy;
#if defined(CURL_DISABLE_VERBOSE_STRINGS) #if defined(CURL_DISABLE_VERBOSE_STRINGS)
(void) easy; (void) easy;
@ -479,13 +480,13 @@ static int events_socket(struct Curl_easy *easy, /* easy handle */
else else
ev->list = nxt; ev->list = nxt;
free(m); free(m);
infof(easy, "socket cb: socket %" FMT_SOCKET_T " REMOVED", s); infof(data, "socket cb: socket %" FMT_SOCKET_T " REMOVED", s);
} }
else { else {
/* The socket 's' is already being monitored, update the activity /* The socket 's' is already being monitored, update the activity
mask. Convert from libcurl bitmask to the poll one. */ mask. Convert from libcurl bitmask to the poll one. */
m->socket.events = socketcb2poll(what); m->socket.events = socketcb2poll(what);
infof(easy, "socket cb: socket %" FMT_SOCKET_T infof(data, "socket cb: socket %" FMT_SOCKET_T
" UPDATED as %s%s", s, " UPDATED as %s%s", s,
(what&CURL_POLL_IN) ? "IN" : "", (what&CURL_POLL_IN) ? "IN" : "",
(what&CURL_POLL_OUT) ? "OUT" : ""); (what&CURL_POLL_OUT) ? "OUT" : "");
@ -499,7 +500,7 @@ static int events_socket(struct Curl_easy *easy, /* easy handle */
if(!found) { if(!found) {
if(what == CURL_POLL_REMOVE) { if(what == CURL_POLL_REMOVE) {
/* should not happen if our logic is correct, but is no drama. */ /* should not happen if our logic is correct, but is no drama. */
DEBUGF(infof(easy, "socket cb: asked to REMOVE socket %" DEBUGF(infof(data, "socket cb: asked to REMOVE socket %"
FMT_SOCKET_T "but not present!", s)); FMT_SOCKET_T "but not present!", s));
DEBUGASSERT(0); DEBUGASSERT(0);
} }
@ -511,7 +512,7 @@ static int events_socket(struct Curl_easy *easy, /* easy handle */
m->socket.events = socketcb2poll(what); m->socket.events = socketcb2poll(what);
m->socket.revents = 0; m->socket.revents = 0;
ev->list = m; ev->list = m;
infof(easy, "socket cb: socket %" FMT_SOCKET_T " ADDED as %s%s", s, infof(data, "socket cb: socket %" FMT_SOCKET_T " ADDED as %s%s", s,
(what&CURL_POLL_IN) ? "IN" : "", (what&CURL_POLL_IN) ? "IN" : "",
(what&CURL_POLL_OUT) ? "OUT" : ""); (what&CURL_POLL_OUT) ? "OUT" : "");
} }

View File

@ -27,7 +27,7 @@
#include "curl_setup.h" #include "curl_setup.h"
#include "timeval.h" #include "timeval.h"
struct Curl_easy;
void Curl_speedinit(struct Curl_easy *data); void Curl_speedinit(struct Curl_easy *data);
CURLcode Curl_speedcheck(struct Curl_easy *data, CURLcode Curl_speedcheck(struct Curl_easy *data,
struct curltime now); struct curltime now);

View File

@ -167,7 +167,7 @@ struct handle
CURL *h; CURL *h;
}; };
static size_t cb(void *data, size_t size, size_t nmemb, void *clientp) static size_t cb(char *data, size_t size, size_t nmemb, void *clientp)
{ {
size_t realsize = size * nmemb; size_t realsize = size * nmemb;
struct handle *handle = (struct handle *) clientp; struct handle *handle = (struct handle *) clientp;

View File

@ -159,10 +159,10 @@ static size_t read_callback(char *ptr, size_t size, size_t nmemb,
} }
static int progress_callback(void *clientp, static int progress_callback(void *clientp,
double dltotal, curl_off_t dltotal,
double dlnow, curl_off_t dlnow,
double ultotal, curl_off_t ultotal,
double ulnow) curl_off_t ulnow)
{ {
(void)dltotal; (void)dltotal;
(void)dlnow; (void)dlnow;

View File

@ -35,7 +35,7 @@ struct transfer_status {
int http_status; int http_status;
}; };
static size_t header_callback(void *ptr, size_t size, size_t nmemb, static size_t header_callback(char *ptr, size_t size, size_t nmemb,
void *userp) void *userp)
{ {
struct transfer_status *st = (struct transfer_status *)userp; struct transfer_status *st = (struct transfer_status *)userp;
@ -77,7 +77,7 @@ static size_t header_callback(void *ptr, size_t size, size_t nmemb,
return len; return len;
} }
static size_t write_callback(void *ptr, size_t size, size_t nmemb, void *userp) static size_t write_callback(char *ptr, size_t size, size_t nmemb, void *userp)
{ {
struct transfer_status *st = (struct transfer_status *)userp; struct transfer_status *st = (struct transfer_status *)userp;
size_t len = size * nmemb; size_t len = size * nmemb;

View File

@ -27,8 +27,8 @@
#include "warnless.h" #include "warnless.h"
#include "memdebug.h" #include "memdebug.h"
size_t WriteOutput(void *ptr, size_t size, size_t nmemb, void *stream); size_t WriteOutput(char *ptr, size_t size, size_t nmemb, void *stream);
size_t WriteHeader(void *ptr, size_t size, size_t nmemb, void *stream); size_t WriteHeader(char *ptr, size_t size, size_t nmemb, void *stream);
static unsigned long realHeaderSize = 0; static unsigned long realHeaderSize = 0;
@ -82,13 +82,13 @@ test_cleanup:
return res; return res;
} }
size_t WriteOutput(void *ptr, size_t size, size_t nmemb, void *stream) size_t WriteOutput(char *ptr, size_t size, size_t nmemb, void *stream)
{ {
fwrite(ptr, size, nmemb, stream); fwrite(ptr, size, nmemb, stream);
return nmemb * size; return nmemb * size;
} }
size_t WriteHeader(void *ptr, size_t size, size_t nmemb, void *stream) size_t WriteHeader(char *ptr, size_t size, size_t nmemb, void *stream)
{ {
(void)ptr; (void)ptr;
(void)stream; (void)stream;

View File

@ -57,7 +57,7 @@ static int please_continue(void *userp,
return 0; /* go on */ return 0; /* go on */
} }
static size_t header_callback(void *ptr, size_t size, size_t nmemb, static size_t header_callback(char *ptr, size_t size, size_t nmemb,
void *userp) void *userp)
{ {
size_t len = size * nmemb; size_t len = size * nmemb;
@ -66,7 +66,7 @@ static size_t header_callback(void *ptr, size_t size, size_t nmemb,
return len; return len;
} }
static size_t write_callback(void *ptr, size_t size, size_t nmemb, void *userp) static size_t write_callback(char *ptr, size_t size, size_t nmemb, void *userp)
{ {
struct transfer_status *st = (struct transfer_status *)userp; struct transfer_status *st = (struct transfer_status *)userp;
size_t len = size * nmemb; size_t len = size * nmemb;

View File

@ -77,7 +77,7 @@ static void check_time0(CURL *easy, int key, const char *name,
report_time(name, where, tval, !tval); report_time(name, where, tval, !tval);
} }
static size_t header_callback(void *ptr, size_t size, size_t nmemb, static size_t header_callback(char *ptr, size_t size, size_t nmemb,
void *userp) void *userp)
{ {
struct transfer_status *st = (struct transfer_status *)userp; struct transfer_status *st = (struct transfer_status *)userp;
@ -100,7 +100,7 @@ static size_t header_callback(void *ptr, size_t size, size_t nmemb,
return len; return len;
} }
static size_t write_callback(void *ptr, size_t size, size_t nmemb, void *userp) static size_t write_callback(char *ptr, size_t size, size_t nmemb, void *userp)
{ {
struct transfer_status *st = (struct transfer_status *)userp; struct transfer_status *st = (struct transfer_status *)userp;

View File

@ -31,7 +31,7 @@ struct headerinfo {
size_t largest; size_t largest;
}; };
static size_t header(void *ptr, size_t size, size_t nmemb, void *stream) static size_t header(char *ptr, size_t size, size_t nmemb, void *stream)
{ {
size_t headersize = size * nmemb; size_t headersize = size * nmemb;
struct headerinfo *info = (struct headerinfo *)stream; struct headerinfo *info = (struct headerinfo *)stream;

View File

@ -27,7 +27,7 @@
#include <curl/curl.h> #include <curl/curl.h>
static size_t cb_curl(void *buffer, size_t size, size_t nmemb, void *userp) static size_t cb_curl(char *buffer, size_t size, size_t nmemb, void *userp)
{ {
(void)buffer; (void)buffer;
(void)size; (void)size;

View File

@ -46,29 +46,30 @@ struct Ctx {
struct curl_slist *contents; struct curl_slist *contents;
}; };
static size_t write_memory_callback(void *contents, size_t size, static size_t write_memory_callback(char *contents, size_t size,
size_t nmemb, void *userp) { size_t nmemb, void *userp)
/* append the data to contents */ {
size_t realsize = size * nmemb; /* append the data to contents */
struct Ctx *mem = (struct Ctx *)userp; size_t realsize = size * nmemb;
char *data = (char *)malloc(realsize + 1); struct Ctx *mem = (struct Ctx *)userp;
struct curl_slist *item_append = NULL; char *data = (char *)malloc(realsize + 1);
if(!data) { struct curl_slist *item_append = NULL;
printf("not enough memory (malloc returned NULL)\n"); if(!data) {
return 0; printf("not enough memory (malloc returned NULL)\n");
} return 0;
memcpy(data, contents, realsize); }
data[realsize] = '\0'; memcpy(data, contents, realsize);
item_append = curl_slist_append(mem->contents, data); data[realsize] = '\0';
free(data); item_append = curl_slist_append(mem->contents, data);
if(item_append) { free(data);
mem->contents = item_append; if(item_append) {
} mem->contents = item_append;
else { }
printf("not enough memory (curl_slist_append returned NULL)\n"); else {
return 0; printf("not enough memory (curl_slist_append returned NULL)\n");
} return 0;
return realsize; }
return realsize;
} }
static static

View File

@ -141,7 +141,7 @@ static size_t read_callback(char *ptr, size_t size, size_t nmemb, void *stream)
} }
static size_t write_callback(void *ptr, size_t size, size_t nmemb, static size_t write_callback(char *ptr, size_t size, size_t nmemb,
void *stream) void *stream)
{ {
int amount = curlx_uztosi(size * nmemb); int amount = curlx_uztosi(size * nmemb);

View File

@ -52,7 +52,7 @@ static const char *RTP_DATA = "$_1234\n\0Rsdf";
static int rtp_packet_count = 0; static int rtp_packet_count = 0;
static size_t rtp_write(void *ptr, size_t size, size_t nmemb, void *stream) static size_t rtp_write(char *ptr, size_t size, size_t nmemb, void *stream)
{ {
char *data = (char *)ptr; char *data = (char *)ptr;
int channel = RTP_PKT_CHANNEL(data); int channel = RTP_PKT_CHANNEL(data);

View File

@ -32,8 +32,9 @@ struct chunk_data {
}; };
static static
long chunk_bgn(const struct curl_fileinfo *finfo, void *ptr, int remains) long chunk_bgn(const void *f, void *ptr, int remains)
{ {
const struct curl_fileinfo *finfo = f;
struct chunk_data *ch_d = ptr; struct chunk_data *ch_d = ptr;
ch_d->remains = remains; ch_d->remains = remains;

View File

@ -85,10 +85,8 @@ void libtest_debug_dump(const char *timebuf, const char *text, FILE *stream,
} }
int libtest_debug_cb(CURL *handle, curl_infotype type, int libtest_debug_cb(CURL *handle, curl_infotype type,
unsigned char *data, size_t size, char *data, size_t size, void *userp)
void *userp)
{ {
struct libtest_trace_cfg *trace_cfg = userp; struct libtest_trace_cfg *trace_cfg = userp;
const char *text; const char *text;
struct timeval tv; struct timeval tv;
@ -140,6 +138,7 @@ int libtest_debug_cb(CURL *handle, curl_infotype type,
return 0; return 0;
} }
libtest_debug_dump(timebuf, text, stderr, data, size, trace_cfg->nohex); libtest_debug_dump(timebuf, text, stderr, (unsigned char *)data, size,
trace_cfg->nohex);
return 0; return 0;
} }

View File

@ -32,7 +32,6 @@ struct libtest_trace_cfg {
extern struct libtest_trace_cfg libtest_debug_config; extern struct libtest_trace_cfg libtest_debug_config;
int libtest_debug_cb(CURL *handle, curl_infotype type, int libtest_debug_cb(CURL *handle, curl_infotype type,
unsigned char *data, size_t size, char *data, size_t size, void *userp);
void *userp);
#endif /* HEADER_LIBTEST_TESTTRACE_H */ #endif /* HEADER_LIBTEST_TESTTRACE_H */