gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libmicrohttpd] branch master updated (bd9b7be7 -> 6ab9cb0c)


From: gnunet
Subject: [libmicrohttpd] branch master updated (bd9b7be7 -> 6ab9cb0c)
Date: Thu, 02 Jun 2022 16:29:22 +0200

This is an automated email from the git hooks/post-receive script.

karlson2k pushed a change to branch master
in repository libmicrohttpd.

    from bd9b7be7 doc/examples: fixed compiler warnings
     new e583a343 websocket_threaded_example: fixed sprintf() usage, compiler 
warnings
     new 6ab9cb0c Muted compiler warnings for W32 non-TLS build of the lib

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/examples/websocket_threaded_example.c | 86 +++++++++++++++++--------------
 src/include/autoinit_funcs.h              |  5 +-
 src/microhttpd/daemon.c                   |  3 ++
 src/microhttpd/gen_auth.c                 |  3 ++
 src/microhttpd/mhd_send.c                 |  5 +-
 src/microhttpd/mhd_threads.c              |  3 +-
 6 files changed, 62 insertions(+), 43 deletions(-)

diff --git a/src/examples/websocket_threaded_example.c 
b/src/examples/websocket_threaded_example.c
index 11615724..21f58ed3 100644
--- a/src/examples/websocket_threaded_example.c
+++ b/src/examples/websocket_threaded_example.c
@@ -151,9 +151,9 @@ SHA1ProcessMessageBlock (struct SHA1Context *context)
 
   for (i = 0; i < 16; i++)
   {
-    W[i] = context->message_block[i * 4] << 24;
-    W[i] |= context->message_block[i * 4 + 1] << 16;
-    W[i] |= context->message_block[i * 4 + 2] << 8;
+    W[i] = ((uint32_t) context->message_block[i * 4]) << 24;
+    W[i] |= ((uint32_t) context->message_block[i * 4 + 1]) << 16;
+    W[i] |= ((uint32_t) context->message_block[i * 4 + 2]) << 8;
     W[i] |= context->message_block[i * 4 + 3];
   }
   for (i = 16; i < 80; i++)
@@ -237,14 +237,14 @@ SHA1PadMessage (struct SHA1Context *context)
       context->message_block[context->message_block_index++] = 0;
     }
   }
-  context->message_block[56] = context->length_high >> 24;
-  context->message_block[57] = context->length_high >> 16;
-  context->message_block[58] = context->length_high >> 8;
-  context->message_block[59] = context->length_high;
-  context->message_block[60] = context->length_low >> 24;
-  context->message_block[61] = context->length_low >> 16;
-  context->message_block[62] = context->length_low >> 8;
-  context->message_block[63] = context->length_low;
+  context->message_block[56] = (unsigned char) (context->length_high >> 24);
+  context->message_block[57] = (unsigned char) (context->length_high >> 16);
+  context->message_block[58] = (unsigned char) (context->length_high >> 8);
+  context->message_block[59] = (unsigned char) (context->length_high);
+  context->message_block[60] = (unsigned char) (context->length_low >> 24);
+  context->message_block[61] = (unsigned char) (context->length_low >> 16);
+  context->message_block[62] = (unsigned char) (context->length_low >> 8);
+  context->message_block[63] = (unsigned char) (context->length_low);
   SHA1ProcessMessageBlock (context);
 }
 
@@ -298,7 +298,8 @@ SHA1Result (struct SHA1Context *context, unsigned char
   for (i = 0; i < SHA1HashSize; ++i)
   {
     Message_Digest[i]
-      = context->intermediate_hash[i >> 2] >> 8 * (3 - (i & 0x03));
+      = (unsigned char) (context->intermediate_hash[i >> 2]
+                         >> 8 * (3 - (i & 0x03)));
   }
   return SHA1_RESULT_SUCCESS;
 }
@@ -541,9 +542,13 @@ send_all (MHD_socket sock, const unsigned char *buf, 
size_t len)
   ssize_t ret;
   size_t off;
 
-  for (off = 0; off < len; off += ret)
+  for (off = 0; off < len; off += (size_t) ret)
   {
+#if ! defined(_WIN32) || defined(__CYGWIN__)
     ret = send (sock, (const void *) &buf[off], len - off, 0);
+#else  /* Native W32 */
+    ret = send (sock, (const void *) &buf[off], (int) (len - off), 0);
+#endif /* Native W32 */
     if (0 > ret)
     {
       if (EAGAIN == errno)
@@ -562,14 +567,14 @@ send_all (MHD_socket sock, const unsigned char *buf, 
size_t len)
 }
 
 
-static int
+static ssize_t
 ws_send_frame (MHD_socket sock, const char *msg, size_t length)
 {
   unsigned char *response;
   unsigned char frame[10];
   unsigned char idx_first_rdata;
-  int idx_response;
-  int output;
+  size_t idx_response;
+  size_t output;
   MHD_socket isock;
   size_t i;
 
@@ -614,7 +619,7 @@ ws_send_frame (MHD_socket sock, const char *msg, size_t 
length)
   }
   for (i = 0; i < length; i++)
   {
-    response[idx_response] = msg[i];
+    response[idx_response] = (unsigned char) msg[i];
     idx_response++;
   }
   response[idx_response] = '\0';
@@ -630,7 +635,7 @@ ws_send_frame (MHD_socket sock, const char *msg, size_t 
length)
   }
   pthread_mutex_unlock (&MUTEX);
   free (response);
-  return output;
+  return (ssize_t) output;
 }
 
 
@@ -643,7 +648,7 @@ ws_receive_frame (unsigned char *frame, ssize_t *length, 
int *type)
   unsigned char flength;
   unsigned char idx_first_mask;
   unsigned char idx_first_data;
-  ssize_t data_length;
+  size_t data_length;
   int i;
   int j;
 
@@ -663,7 +668,7 @@ ws_receive_frame (unsigned char *frame, ssize_t *length, 
int *type)
       idx_first_mask = 10;
     }
     idx_first_data = idx_first_mask + 4;
-    data_length = *length - idx_first_data;
+    data_length = (size_t) *length - idx_first_data;
     masks[0] = frame[idx_first_mask + 0];
     masks[1] = frame[idx_first_mask + 1];
     masks[2] = frame[idx_first_mask + 2];
@@ -675,7 +680,7 @@ ws_receive_frame (unsigned char *frame, ssize_t *length, 
int *type)
       {
         msg[j] = frame[i] ^ masks[j % 4];
       }
-      *length = data_length;
+      *length = (ssize_t) data_length;
       msg[j] = '\0';
     }
   }
@@ -698,12 +703,9 @@ run_usock (void *cls)
   struct MHD_UpgradeResponseHandle *urh = ws->urh;
   unsigned char buf[2048];
   unsigned char *msg;
-  char client[20];
   char *text;
   ssize_t got;
-  size_t size;
   int type;
-  int sent;
   int i;
 
   make_blocking (ws->sock);
@@ -721,19 +723,26 @@ run_usock (void *cls)
     }
     if (type == WS_OPCODE_TEXT_FRAME)
     {
-      size = sprintf (client, "User#%d: ", (int) ws->sock);
-      size += got;
-      text = malloc (size);
-      if (NULL != text)
+      ssize_t sent;
+      int buf_size;
+      buf_size = snprintf (NULL, 0, "User#%d: %s", (int) ws->sock, msg);
+      if (0 < buf_size)
       {
-        sprintf (text, "%s%s", client, msg);
-        sent = ws_send_frame (ws->sock, text, size);
-        free (text);
+        text = malloc ((size_t) buf_size + 1);
+        if (NULL != text)
+        {
+          if (snprintf (text, (size_t) buf_size + 1,
+                        "User#%d: %s", (int) ws->sock, msg) == buf_size)
+            sent = ws_send_frame (ws->sock, text, (size_t) buf_size);
+          else
+            sent = -1;
+          free (text);
+        }
+        else
+          sent = -1;
       }
       else
-      {
         sent = -1;
-      }
       free (msg);
       if (-1 == sent)
       {
@@ -888,18 +897,19 @@ int
 main (int argc, char *const *argv)
 {
   struct MHD_Daemon *d;
-  uint16_t port;
+  unsigned int port;
   size_t i;
-
-  if (argc != 2)
+  if ( (argc != 2) ||
+       (1 != sscanf (argv[1], "%u", &port)) ||
+       (65535 < port) )
   {
     printf ("%s PORT\n", argv[0]);
     return 1;
   }
-  port = atoi (argv[1]);
   d = MHD_start_daemon (MHD_ALLOW_UPGRADE | MHD_USE_AUTO_INTERNAL_THREAD
                         | MHD_USE_ERROR_LOG,
-                        port, NULL, NULL, &ahc_cb, &port, MHD_OPTION_END);
+                        (uint16_t) port, NULL, NULL,
+                        &ahc_cb, NULL, MHD_OPTION_END);
   if (NULL == d)
     return 1;
   for (i = 0; i < sizeof(CLIENT_SOCKS) / sizeof(CLIENT_SOCKS[0]); ++i)
diff --git a/src/include/autoinit_funcs.h b/src/include/autoinit_funcs.h
index adf66460..1636db7f 100644
--- a/src/include/autoinit_funcs.h
+++ b/src/include/autoinit_funcs.h
@@ -67,7 +67,7 @@
 * Current version of the header in packed BCD form.
 * 0x01093001 = 1.9.30-1.
 */
-#define AUTOINIT_FUNCS_VERSION 0x01000400
+#define AUTOINIT_FUNCS_VERSION 0x01000500
 
 #if defined(__GNUC__) || defined(__clang__)
 /* if possible - check for supported attribute */
@@ -221,7 +221,8 @@
 #define W32_SET_INIT_AND_DEINIT(FI,FD) \
   BOOL WINAPI DllMain (HINSTANCE hinst,DWORD reason,LPVOID unused); \
   BOOL WINAPI DllMain (HINSTANCE hinst,DWORD reason,LPVOID unused)  \
-  { if (DLL_PROCESS_ATTACH==reason) {(void) (FI) ();} \
+  { (void) hinst; (void) unused; \
+    if (DLL_PROCESS_ATTACH==reason) {(void) (FI) ();} \
     else if (DLL_PROCESS_DETACH==reason) {(void) (FD) ();} \
     return TRUE; \
   } struct _W32_dummy_strc_ ## FI {int i;}
diff --git a/src/microhttpd/daemon.c b/src/microhttpd/daemon.c
index 6ac948d9..faa6d3e9 100644
--- a/src/microhttpd/daemon.c
+++ b/src/microhttpd/daemon.c
@@ -2676,8 +2676,11 @@ new_connection_prepare_ (struct MHD_Daemon *daemon,
     free (connection->addr);
     free (connection);
     MHD_PANIC (_ ("TLS connection on non-TLS daemon.\n"));
+#if 0
+    /* Unreachable code */
     eno = EINVAL;
     return NULL;
+#endif
 #endif /* ! HTTPS_SUPPORT */
   }
 
diff --git a/src/microhttpd/gen_auth.c b/src/microhttpd/gen_auth.c
index e993fb20..0246a114 100644
--- a/src/microhttpd/gen_auth.c
+++ b/src/microhttpd/gen_auth.c
@@ -298,7 +298,10 @@ parse_dauth_params (const char *str,
         param_str = buf;
       }
       else
+      {
         param_len = 0;
+        param_str = NULL; /* Actually not used */
+      }
     }
     if ((param_len == 4) && MHD_str_equal_caseless_bin_n_ (param_str, "true",
                                                            4))
diff --git a/src/microhttpd/mhd_send.c b/src/microhttpd/mhd_send.c
index e632406e..ae763b9b 100644
--- a/src/microhttpd/mhd_send.c
+++ b/src/microhttpd/mhd_send.c
@@ -822,8 +822,9 @@ MHD_send_data_ (struct MHD_Connection *connection,
      * sent amount smaller than provided amount, as TLS
      * connections may break data into smaller parts for sending. */
 #endif /* EPOLL_SUPPORT */
-#endif /* HTTPS_SUPPORT  */
-    (void) 0; /* Mute compiler warning for non-TLS builds. */
+#else  /* ! HTTPS_SUPPORT  */
+    ret = MHD_ERR_NOTCONN_;
+#endif /* ! HTTPS_SUPPORT  */
   }
   else
   {
diff --git a/src/microhttpd/mhd_threads.c b/src/microhttpd/mhd_threads.c
index 628a628f..95fc70a6 100644
--- a/src/microhttpd/mhd_threads.c
+++ b/src/microhttpd/mhd_threads.c
@@ -163,7 +163,8 @@ MHD_set_thread_name_ (const MHD_thread_ID_ thread_id,
  * @param n name to set
  * @return non-zero on success, zero otherwise
  */
-#define MHD_set_cur_thread_name_(n) MHD_set_thread_name_ (-1,(n))
+#define MHD_set_cur_thread_name_(n) \
+  MHD_set_thread_name_ ((MHD_thread_ID_) -1,(n))
 #endif /* _MSC_FULL_VER */
 #endif /* MHD_USE_W32_THREADS */
 

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]