]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
tests: fix callback signatures to please UndefinedBehaviorSanitizer 15289/head
authorDaniel Stenberg <daniel@haxx.se>
Mon, 14 Oct 2024 11:01:19 +0000 (13:01 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Tue, 15 Oct 2024 12:33:47 +0000 (14:33 +0200)
Make test applications use the correct prototypes for callbacks.

Closes #15289

17 files changed:
lib/doh.c
lib/easy.c
lib/speedcheck.h
tests/http/clients/h2-pausing.c
tests/http/clients/upload-pausing.c
tests/libtest/lib1485.c
tests/libtest/lib1509.c
tests/libtest/lib1540.c
tests/libtest/lib1541.c
tests/libtest/lib1556.c
tests/libtest/lib2308.c
tests/libtest/lib3207.c
tests/libtest/lib552.c
tests/libtest/lib571.c
tests/libtest/lib576.c
tests/libtest/testtrace.c
tests/libtest/testtrace.h

index 8a9b02367266272406f54d1d38dfd9f51e4309fa..1873d413b70d3720c0dc24be4222d1f352c1a584 100644 (file)
--- a/lib/doh.c
+++ b/lib/doh.c
@@ -180,7 +180,7 @@ UNITTEST DOHcode doh_req_encode(const char *host,
 }
 
 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;
   struct dynbuf *mem = (struct dynbuf *)userp;
index 8a18023736fb64671065e0b3644271703bfa3611..d16fa8c07afec00ab6186880eff05c925da00380 100644 (file)
@@ -398,9 +398,9 @@ struct events {
  * Callback that gets called with a new value when the timeout should be
  * updated.
  */
-static int events_timer(struct Curl_multi *multi,    /* multi handle */
+static int events_timer(CURLM *multi,    /* multi handle */
                         long timeout_ms, /* see above */
-                        void *userp)    /* private callback pointer */
+                        void *userp)     /* private callback pointer */
 {
   struct events *ev = userp;
   (void)multi;
@@ -449,7 +449,7 @@ static short socketcb2poll(int pollmask)
  * Callback that gets called with information about socket activity to
  * monitor.
  */
-static int events_socket(struct Curl_easy *easy,      /* easy handle */
+static int events_socket(CURL *easy,      /* easy handle */
                          curl_socket_t s, /* socket */
                          int what,        /* see above */
                          void *userp,     /* private callback
@@ -461,6 +461,7 @@ static int events_socket(struct Curl_easy *easy,      /* easy handle */
   struct socketmonitor *m;
   struct socketmonitor *prev = NULL;
   bool found = FALSE;
+  struct Curl_easy *data = easy;
 
 #if defined(CURL_DISABLE_VERBOSE_STRINGS)
   (void) easy;
@@ -479,13 +480,13 @@ static int events_socket(struct Curl_easy *easy,      /* easy handle */
         else
           ev->list = nxt;
         free(m);
-        infof(easy, "socket cb: socket %" FMT_SOCKET_T " REMOVED", s);
+        infof(data, "socket cb: socket %" FMT_SOCKET_T " REMOVED", s);
       }
       else {
         /* The socket 's' is already being monitored, update the activity
            mask. Convert from libcurl bitmask to the poll one. */
         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,
               (what&CURL_POLL_IN) ? "IN" : "",
               (what&CURL_POLL_OUT) ? "OUT" : "");
@@ -499,7 +500,7 @@ static int events_socket(struct Curl_easy *easy,      /* easy handle */
   if(!found) {
     if(what == CURL_POLL_REMOVE) {
       /* 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));
       DEBUGASSERT(0);
     }
@@ -511,7 +512,7 @@ static int events_socket(struct Curl_easy *easy,      /* easy handle */
         m->socket.events = socketcb2poll(what);
         m->socket.revents = 0;
         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_OUT) ? "OUT" : "");
       }
index bff2f32b774023b549d5158d85578cf280c2e9a3..8b116f15289d5ad61c86bbdc70426e54cda82ec9 100644 (file)
@@ -27,7 +27,7 @@
 #include "curl_setup.h"
 
 #include "timeval.h"
-
+struct Curl_easy;
 void Curl_speedinit(struct Curl_easy *data);
 CURLcode Curl_speedcheck(struct Curl_easy *data,
                          struct curltime now);
index a0c111148bba151e7f80210055ac96274c82e098..1fd54d4f6375f122c8eeb9d1e6da654ebaa8f3e9 100644 (file)
@@ -167,7 +167,7 @@ struct handle
   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;
   struct handle *handle = (struct handle *) clientp;
index 272d4157f42ecd76220df4feb30793bade2116f5..ff68b7bd1450d0b4ed075a0fa1de480b4a50b31e 100644 (file)
@@ -159,10 +159,10 @@ static size_t read_callback(char *ptr, size_t size, size_t nmemb,
 }
 
 static int progress_callback(void *clientp,
-                             double dltotal,
-                             double dlnow,
-                             double ultotal,
-                             double ulnow)
+                             curl_off_t dltotal,
+                             curl_off_t dlnow,
+                             curl_off_t ultotal,
+                             curl_off_t ulnow)
 {
   (void)dltotal;
   (void)dlnow;
index e1710ee2f9e63a8824f962225c55234a3ce7ba8b..650746a37816ca8ffe54d15fb76f87a0017a0413 100644 (file)
@@ -35,7 +35,7 @@ struct transfer_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)
 {
   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;
 }
 
-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;
   size_t len = size * nmemb;
index d60f2500688ff365dd342fa66c296e4bcee94a90..328ebd5d066f6f1aaba6ca78f45f45c47dc6a249 100644 (file)
@@ -27,8 +27,8 @@
 #include "warnless.h"
 #include "memdebug.h"
 
-size_t WriteOutput(void *ptr, size_t size, size_t nmemb, void *stream);
-size_t WriteHeader(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(char *ptr, size_t size, size_t nmemb, void *stream);
 
 static unsigned long realHeaderSize = 0;
 
@@ -82,13 +82,13 @@ test_cleanup:
   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);
   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)stream;
index 714d5d5e7cf2538e72bd1a7a1a5451a19a1798b2..210879447ec508b0039abc621c7c9320f81df0ff 100644 (file)
@@ -57,7 +57,7 @@ static int please_continue(void *userp,
   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)
 {
   size_t len = size * nmemb;
@@ -66,7 +66,7 @@ static size_t header_callback(void *ptr, size_t size, size_t nmemb,
   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;
   size_t len = size * nmemb;
index 640a2f16900992accd80bb773dc85c4c5bb9e364..a60d61a7eca4ae3329e6fca729da280207004870 100644 (file)
@@ -77,7 +77,7 @@ static void check_time0(CURL *easy, int key, const char *name,
     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)
 {
   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;
 }
 
-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;
 
index 5b05ff0ef41085e38a518fbbdc51a41cf93715d9..25be5e50fa8a37a35d656392be527adcd99cc47d 100644 (file)
@@ -31,7 +31,7 @@ struct headerinfo {
   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;
   struct headerinfo *info = (struct headerinfo *)stream;
index 7751a1505277ee3cde340cad5b059310c4d9b835..47e0763c81515912a81faa61b2ce4d6de6f0e819 100644 (file)
@@ -27,7 +27,7 @@
 
 #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)size;
index 6c819b3596f2f7d63a52dcd2abf19cf1ea336772..a78608156d2c5bdbbc79d5d01167d9a1866f2561 100644 (file)
@@ -46,29 +46,30 @@ struct Ctx {
   struct curl_slist *contents;
 };
 
-static size_t write_memory_callback(void *contents, size_t size,
-  size_t nmemb, void *userp) {
-    /* append the data to contents */
-    size_t realsize = size * nmemb;
-    struct Ctx *mem = (struct Ctx *)userp;
-    char *data = (char *)malloc(realsize + 1);
-    struct curl_slist *item_append = NULL;
-    if(!data) {
-      printf("not enough memory (malloc returned NULL)\n");
-      return 0;
-    }
-    memcpy(data, contents, realsize);
-    data[realsize] = '\0';
-    item_append = curl_slist_append(mem->contents, data);
-    free(data);
-    if(item_append) {
-      mem->contents = item_append;
-    }
-    else {
-      printf("not enough memory (curl_slist_append returned NULL)\n");
-      return 0;
-    }
-    return realsize;
+static size_t write_memory_callback(char *contents, size_t size,
+                                    size_t nmemb, void *userp)
+{
+  /* append the data to contents */
+  size_t realsize = size * nmemb;
+  struct Ctx *mem = (struct Ctx *)userp;
+  char *data = (char *)malloc(realsize + 1);
+  struct curl_slist *item_append = NULL;
+  if(!data) {
+    printf("not enough memory (malloc returned NULL)\n");
+    return 0;
+  }
+  memcpy(data, contents, realsize);
+  data[realsize] = '\0';
+  item_append = curl_slist_append(mem->contents, data);
+  free(data);
+  if(item_append) {
+    mem->contents = item_append;
+  }
+  else {
+    printf("not enough memory (curl_slist_append returned NULL)\n");
+    return 0;
+  }
+  return realsize;
 }
 
 static
index 76244ab339374367b4667e82f5844377de2380c7..0920b025a8ae30fd94b3d6ff4101544ab3da82c3 100644 (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)
 {
   int amount = curlx_uztosi(size * nmemb);
index 65798899952dbcabdcf84ea5a102f41f0e14a072..b7868e0a32f73d2f7d9d9a5fc05078d4b36fac4d 100644 (file)
@@ -52,7 +52,7 @@ static const char *RTP_DATA = "$_1234\n\0Rsdf";
 
 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;
   int channel = RTP_PKT_CHANNEL(data);
index 784f22d3f36e782f7a1989b67551a459ebf71a37..db5a41aad6ccc2dbbb8bc3f5992537dd1ff1a3b4 100644 (file)
@@ -32,8 +32,9 @@ struct chunk_data {
 };
 
 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;
   ch_d->remains = remains;
 
index 49ff8ae20efbcf79191fb3fbfa61b794420e1551..fd4cb5bb47b6d52528040fa97844d9949c097fce 100644 (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,
-                     unsigned char *data, size_t size,
-                     void *userp)
+                     char *data, size_t size, void *userp)
 {
-
   struct libtest_trace_cfg *trace_cfg = userp;
   const char *text;
   struct timeval tv;
@@ -140,6 +138,7 @@ int libtest_debug_cb(CURL *handle, curl_infotype type,
     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;
 }
index 35f27b0965447f592fabba66b9cce527f6a947b2..d7087c5366fa5acbbc779a26d5701c659bacae2f 100644 (file)
@@ -32,7 +32,6 @@ struct libtest_trace_cfg {
 extern struct libtest_trace_cfg libtest_debug_config;
 
 int libtest_debug_cb(CURL *handle, curl_infotype type,
-                     unsigned char *data, size_t size,
-                     void *userp);
+                     char *data, size_t size, void *userp);
 
 #endif /* HEADER_LIBTEST_TESTTRACE_H */