gnunet-svn
[Top][All Lists]
Advanced

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

[libmicrohttpd] 02/02: doc/examples: fixed compiler warnings


From: gnunet
Subject: [libmicrohttpd] 02/02: doc/examples: fixed compiler warnings
Date: Thu, 02 Jun 2022 08:43:24 +0200

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

karlson2k pushed a commit to branch master
in repository libmicrohttpd.

commit bd9b7be7322fc548d7f22149d8aaf9dd234bb0e7
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
AuthorDate: Thu Jun 2 09:43:12 2022 +0300

    doc/examples: fixed compiler warnings
---
 doc/examples/largepost.c         |  2 +-
 doc/examples/responseheaders.c   |  2 +-
 doc/examples/sessions.c          | 23 ++++++++++++++++++-----
 doc/examples/tlsauthentication.c |  8 ++++----
 4 files changed, 24 insertions(+), 11 deletions(-)

diff --git a/doc/examples/largepost.c b/doc/examples/largepost.c
index 41f4ed12..8669bc28 100644
--- a/doc/examples/largepost.c
+++ b/doc/examples/largepost.c
@@ -93,7 +93,7 @@ static const char *const postprocerror =
 static enum MHD_Result
 send_page (struct MHD_Connection *connection,
            const char *page,
-           int status_code)
+           unsigned int status_code)
 {
   enum MHD_Result ret;
   struct MHD_Response *response;
diff --git a/doc/examples/responseheaders.c b/doc/examples/responseheaders.c
index ce8167f3..30ac4596 100644
--- a/doc/examples/responseheaders.c
+++ b/doc/examples/responseheaders.c
@@ -63,7 +63,7 @@ answer_to_connection (void *cls, struct MHD_Connection 
*connection,
       return MHD_NO;
   }
   response =
-    MHD_create_response_from_fd_at_offset64 (sbuf.st_size, fd, 0);
+    MHD_create_response_from_fd_at_offset64 ((size_t) sbuf.st_size, fd, 0);
   MHD_add_response_header (response, "Content-Type", MIMETYPE);
   ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
   MHD_destroy_response (response);
diff --git a/doc/examples/sessions.c b/doc/examples/sessions.c
index 7f62e73b..de864382 100644
--- a/doc/examples/sessions.c
+++ b/doc/examples/sessions.c
@@ -33,7 +33,7 @@ MHD_asprintf (char **resultp, const char *format, ...)
     size_t buf_size;
     char *buf;
 
-    buf_size = len + 1;
+    buf_size = (size_t) len + 1;
     buf = (char *) malloc (buf_size * sizeof(char));
     if (NULL != buf)
     {
@@ -406,7 +406,7 @@ fill_v1_v2_form (const void *cls,
   }
   /* return static form */
   response =
-    MHD_create_response_from_buffer_with_free_callback (reply_len,
+    MHD_create_response_from_buffer_with_free_callback ((size_t) reply_len,
                                                         (void *) reply,
                                                         &free);
   add_session_cookie (session, response);
@@ -749,16 +749,25 @@ main (int argc, char *const *argv)
   fd_set es;
   MHD_socket max;
   uint64_t mhd_timeout;
+  unsigned int port;
 
   if (argc != 2)
   {
     printf ("%s PORT\n", argv[0]);
     return 1;
   }
+  if ( (1 != sscanf (argv[1], "%u", &port)) ||
+       (0 == port) || (65535 < port) )
+  {
+    fprintf (stderr,
+             "Port must be a number between 1 and 65535.\n");
+    return 1;
+  }
+
   /* initialize PRNG */
   srand ((unsigned int) time (NULL));
   d = MHD_start_daemon (MHD_USE_ERROR_LOG,
-                        atoi (argv[1]),
+                        (uint16_t) port,
                         NULL, NULL,
                         &create_response, NULL,
                         MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 15,
@@ -778,13 +787,17 @@ main (int argc, char *const *argv)
       break; /* fatal internal error */
     if (MHD_get_timeout64 (d, &mhd_timeout) == MHD_YES)
     {
-      tv.tv_sec = (time_t) mhd_timeout / 1000;
+#if ! defined(_WIN32) || defined(__CYGWIN__)
+      tv.tv_sec = (time_t) (mhd_timeout / 1000);
+#else  /* Native W32 */
+      tv.tv_sec = (long) (mhd_timeout / 1000);
+#endif /* Native W32 */
       tv.tv_usec = ((long) (mhd_timeout % 1000)) * 1000;
       tvp = &tv;
     }
     else
       tvp = NULL;
-    if (-1 == select (max + 1, &rs, &ws, &es, tvp))
+    if (-1 == select ((int) max + 1, &rs, &ws, &es, tvp))
     {
       if (EINTR != errno)
         fprintf (stderr,
diff --git a/doc/examples/tlsauthentication.c b/doc/examples/tlsauthentication.c
index 57556d0b..65d9d8db 100644
--- a/doc/examples/tlsauthentication.c
+++ b/doc/examples/tlsauthentication.c
@@ -65,7 +65,7 @@ string_to_base64 (const char *message)
 }
 
 
-static long
+static size_t
 get_file_size (const char *filename)
 {
   FILE *fp;
@@ -80,7 +80,7 @@ get_file_size (const char *filename)
 
     fclose (fp);
 
-    return size;
+    return (size_t) size;
   }
   else
     return 0;
@@ -92,7 +92,7 @@ load_file (const char *filename)
 {
   FILE *fp;
   char *buffer;
-  long size;
+  size_t size;
 
   size = get_file_size (filename);
   if (0 == size)
@@ -110,7 +110,7 @@ load_file (const char *filename)
   }
   buffer[size] = '\0';
 
-  if (size != (long) fread (buffer, 1, size, fp))
+  if (size != fread (buffer, 1, size, fp))
   {
     free (buffer);
     buffer = NULL;

-- 
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]