瀏覽代碼

doc/examples: fixed compiler warnings

Evgeny Grin (Karlson2k) 3 年之前
父節點
當前提交
bd9b7be732
共有 4 個文件被更改,包括 24 次插入11 次删除
  1. 1 1
      doc/examples/largepost.c
  2. 1 1
      doc/examples/responseheaders.c
  3. 18 5
      doc/examples/sessions.c
  4. 4 4
      doc/examples/tlsauthentication.c

+ 1 - 1
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;

+ 1 - 1
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);

+ 18 - 5
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,

+ 4 - 4
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;