gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [libmicrohttpd] branch master updated: some minor code clea


From: gnunet
Subject: [GNUnet-SVN] [libmicrohttpd] branch master updated: some minor code cleaning issues
Date: Fri, 22 Jun 2018 15:18:38 +0200

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

grothoff pushed a commit to branch master
in repository libmicrohttpd.

The following commit(s) were added to refs/heads/master by this push:
     new 83273955 some minor code cleaning issues
83273955 is described below

commit 832739556b765571f80520b91bdad5f14f6aa1b4
Author: Christian Grothoff <address@hidden>
AuthorDate: Fri Jun 22 15:16:11 2018 +0200

    some minor code cleaning issues
---
 doc/examples/tlsauthentication.c             |  8 ++--
 po/remove-potcdate.sed                       | 11 -----
 src/examples/demo_https.c                    |  2 +-
 src/examples/querystring_example.c           | 12 ++++-
 src/examples/suspend_resume_epoll.c          | 68 ++++++++++++++++------------
 src/lib/connection_add.c                     |  3 +-
 src/lib/connection_call_handlers.c           | 12 ++---
 src/lib/daemon_start.c                       |  4 +-
 src/microhttpd/connection.c                  | 12 ++---
 src/testcurl/https/test_tls_authentication.c |  8 ++--
 src/testcurl/test_callback.c                 | 13 ++++--
 src/testcurl/test_get_chunked.c              |  7 ++-
 src/testzzuf/test_get_chunked.c              | 18 ++++++--
 src/testzzuf/test_long_header.c              |  7 +--
 14 files changed, 107 insertions(+), 78 deletions(-)

diff --git a/doc/examples/tlsauthentication.c b/doc/examples/tlsauthentication.c
index 4c512a3b..43b41bf1 100644
--- a/doc/examples/tlsauthentication.c
+++ b/doc/examples/tlsauthentication.c
@@ -33,12 +33,10 @@ string_to_base64 (const char *message)
   char *tmp;
   size_t length = strlen (message);
 
-  tmp = malloc (length * 2);
+  tmp = malloc (length * 2 + 1);
   if (NULL == tmp)
-    return tmp;
-
+    return NULL;
   tmp[0] = 0;
-
   for (i = 0; i < length; i += 3)
     {
       l = (((unsigned long) message[i]) << 16)
@@ -169,7 +167,7 @@ is_authenticated (struct MHD_Connection *connection,
   const char *strbase = "Basic ";
   int authenticated;
   size_t slen;
-  
+
   headervalue =
     MHD_lookup_connection_value (connection, MHD_HEADER_KIND,
                                  "Authorization");
diff --git a/po/remove-potcdate.sed b/po/remove-potcdate.sed
deleted file mode 100644
index edb38d70..00000000
--- a/po/remove-potcdate.sed
+++ /dev/null
@@ -1,11 +0,0 @@
-/^"POT-Creation-Date: .*"$/{
-x
-s/P/P/
-ta
-g
-d
-bb
-:a
-x
-:b
-}
diff --git a/src/examples/demo_https.c b/src/examples/demo_https.c
index 88b01bbf..d5542eab 100644
--- a/src/examples/demo_https.c
+++ b/src/examples/demo_https.c
@@ -561,7 +561,7 @@ process_upload_data (void *cls,
                uc->category,
                filename);
       for (i=strlen (fn)-1;i>=0;i--)
-       if (! isprint ((int) fn[i]))
+       if (! isprint ((unsigned char) fn[i]))
          fn[i] = '_';
       uc->fd = open (fn,
                     O_CREAT | O_EXCL
diff --git a/src/examples/querystring_example.c 
b/src/examples/querystring_example.c
index 3d91bcea..db0d6f1a 100644
--- a/src/examples/querystring_example.c
+++ b/src/examples/querystring_example.c
@@ -77,16 +77,24 @@ int
 main (int argc, char *const *argv)
 {
   struct MHD_Daemon *d;
+  int port;
 
   if (argc != 2)
     {
       printf ("%s PORT\n", argv[0]);
       return 1;
     }
+  port = atoi (argv[1]);
+  if ( (port < 0) ||
+       (port > UINT16_MAX) )
+    {
+      printf ("%s PORT\n", argv[0]);
+      return 1;
+    }
   d = MHD_start_daemon (MHD_USE_THREAD_PER_CONNECTION | 
MHD_USE_INTERNAL_POLLING_THREAD | MHD_USE_ERROR_LOG,
-                        atoi (argv[1]),
+                        (uint16_t) port,
                         NULL, NULL, &ahc_echo, PAGE, MHD_OPTION_END);
-  if (d == NULL)
+  if (NULL == d)
     return 1;
   (void) getc (stdin);
   MHD_stop_daemon (d);
diff --git a/src/examples/suspend_resume_epoll.c 
b/src/examples/suspend_resume_epoll.c
index adff673c..4007cc94 100644
--- a/src/examples/suspend_resume_epoll.c
+++ b/src/examples/suspend_resume_epoll.c
@@ -54,69 +54,77 @@ ahc_echo (void *cls,
   int ret;
   struct Request* req;
   struct itimerspec ts;
-  (void)url;               /* Unused. Silence compiler warning. */
-  (void)version;           /* Unused. Silence compiler warning. */
-  (void)upload_data;       /* Unused. Silence compiler warning. */
-  (void)upload_data_size;  /* Unused. Silence compiler warning. */
 
+  (void) url;               /* Unused. Silence compiler warning. */
+  (void) version;           /* Unused. Silence compiler warning. */
+  (void) upload_data;       /* Unused. Silence compiler warning. */
+  (void) upload_data_size;  /* Unused. Silence compiler warning. */
   req = *ptr;
-  if (!req)
+  if (NULL == req)
   {
 
-    req = malloc(sizeof(struct Request));
+    req = malloc (sizeof(struct Request));
+    if (NULL == req)
+      return MHD_NO;
     req->connection = connection;
-    req->timerfd = 0;
+    req->timerfd = -1;
     *ptr = req;
     return MHD_YES;
   }
 
-  if (req->timerfd)
+  if (-1 != req->timerfd)
   {
     // send response (echo request url)
     response = MHD_create_response_from_buffer (strlen (url),
                                                 (void *) url,
                                                 MHD_RESPMEM_MUST_COPY);
-    ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
+    if (NULL == response)
+      return MHD_NO;
+    ret = MHD_queue_response (connection,
+                              MHD_HTTP_OK,
+                              response);
     MHD_destroy_response (response);
     return ret;
   }
-  else
-  {
-    // create timer and suspend connection
-    req->timerfd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK);
-    if (-1 == req->timerfd)
+  // create timer and suspend connection
+  req->timerfd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK);
+  if (-1 == req->timerfd)
     {
       printf("timerfd_create: %s", strerror(errno));
       return MHD_NO;
     }
-    evt.events = EPOLLIN;
-    evt.data.ptr = req;
-    if (-1 == epoll_ctl(epfd, EPOLL_CTL_ADD, req->timerfd, &evt))
+  evt.events = EPOLLIN;
+  evt.data.ptr = req;
+  if (-1 == epoll_ctl(epfd, EPOLL_CTL_ADD, req->timerfd, &evt))
     {
       printf("epoll_ctl: %s", strerror(errno));
       return MHD_NO;
     }
-    ts.it_value.tv_sec = 1;
-    ts.it_value.tv_nsec = 0;
-    ts.it_interval.tv_sec = 0;
-    ts.it_interval.tv_nsec = 0;
-    if (-1 == timerfd_settime(req->timerfd, 0, &ts, NULL))
+  ts.it_value.tv_sec = 1;
+  ts.it_value.tv_nsec = 0;
+  ts.it_interval.tv_sec = 0;
+  ts.it_interval.tv_nsec = 0;
+  if (-1 == timerfd_settime(req->timerfd, 0, &ts, NULL))
     {
       printf("timerfd_settime: %s", strerror(errno));
       return MHD_NO;
     }
-    MHD_suspend_connection(connection);
-    return MHD_YES;
-  }
+  MHD_suspend_connection(connection);
+  return MHD_YES;
 }
 
 
-static int
-connection_done(struct MHD_Connection *connection,
-                void **con_cls,
-                enum MHD_RequestTerminationCode toe)
+static void
+connection_done (void *cls,
+                 struct MHD_Connection *connection,
+                 void **con_cls,
+                 enum MHD_RequestTerminationCode toe)
 {
-  free(*con_cls);
+  struct Request *req = *con_cls;
+
+  if (-1 != req->timerfd)
+    close (req->timerfd);
+  free(req);
 }
 
 
diff --git a/src/lib/connection_add.c b/src/lib/connection_add.c
index 570a6a09..b6f8f0ea 100644
--- a/src/lib/connection_add.c
+++ b/src/lib/connection_add.c
@@ -896,7 +896,8 @@ internal_add_connection (struct MHD_Daemon *daemon,
                                  connection,
                                  MHD_CONNECTION_NOTIFY_CLOSED);
 #ifdef HTTPS_SUPPORT
- if (NULL != connection->tls_cs)
+  if ( (NULL != daemon->tls_api) &&
+       (NULL != connection->tls_cs) )
    daemon->tls_api->teardown_connection (daemon->tls_api->cls,
                                         connection->tls_cs);
 #endif /* HTTPS_SUPPORT */
diff --git a/src/lib/connection_call_handlers.c 
b/src/lib/connection_call_handlers.c
index ab909da8..92b0e8f7 100644
--- a/src/lib/connection_call_handlers.c
+++ b/src/lib/connection_call_handlers.c
@@ -3372,12 +3372,12 @@ MHD_request_handle_idle_ (struct MHD_Request *request)
                 }
 #endif
               /* Response is not required anymore for this request. */
-              if (NULL != request->response)
-                {
-                  struct MHD_Response * const resp = request->response;
-                  request->response = NULL;
-                  MHD_response_queue_for_destroy (resp);
-                }
+              {
+                struct MHD_Response * const resp = request->response;
+
+                request->response = NULL;
+                MHD_response_queue_for_destroy (resp);
+              }
               continue;
             }
 #endif /* UPGRADE_SUPPORT */
diff --git a/src/lib/daemon_start.c b/src/lib/daemon_start.c
index 617a527a..2596b725 100644
--- a/src/lib/daemon_start.c
+++ b/src/lib/daemon_start.c
@@ -163,7 +163,7 @@ open_listen_socket (struct MHD_Daemon *daemon)
 
   if (MHD_INVALID_SOCKET != daemon->listen_socket)
     return MHD_SC_OK; /* application opened it for us! */
-
+  pf = -1;
   /* Determine address family */
   switch (daemon->listen_af)
     {
@@ -224,7 +224,7 @@ open_listen_socket (struct MHD_Daemon *daemon)
       return MHD_SC_IPV6_NOT_SUPPORTED_BY_BUILD;
 #endif
     }
-
+  mhd_assert (-1 != pf);
   /* try to open listen socket */
  try_open_listen_socket:
   daemon->listen_socket = MHD_socket_create_listen_(pf);
diff --git a/src/microhttpd/connection.c b/src/microhttpd/connection.c
index 9c2ea2da..13b5015b 100644
--- a/src/microhttpd/connection.c
+++ b/src/microhttpd/connection.c
@@ -3538,12 +3538,12 @@ MHD_connection_handle_idle (struct MHD_Connection 
*connection)
                   continue;
                 }
               /* Response is not required anymore for this connection. */
-              if (NULL != connection->response)
-                {
-                  struct MHD_Response * const resp = connection->response;
-                  connection->response = NULL;
-                  MHD_destroy_response (resp);
-                }
+              {
+                struct MHD_Response * const resp = connection->response;
+
+                connection->response = NULL;
+                MHD_destroy_response (resp);
+              }
               continue;
             }
 #endif /* UPGRADE_SUPPORT */
diff --git a/src/testcurl/https/test_tls_authentication.c 
b/src/testcurl/https/test_tls_authentication.c
index 7a6cd9a4..2ed8f14c 100644
--- a/src/testcurl/https/test_tls_authentication.c
+++ b/src/testcurl/https/test_tls_authentication.c
@@ -86,7 +86,9 @@ main (int argc, char *const *argv)
 {
   unsigned int errorCount = 0;
   char *aes256_sha = "AES256-SHA";
-  (void)argc; (void)argv;       /* Unused. Silent compiler warning. */
+  FILE *crt;
+  (void)argc;
+  (void)argv;       /* Unused. Silent compiler warning. */
 
 #ifdef MHD_HTTPS_REQUIRE_GRYPT
   gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0);
@@ -103,13 +105,13 @@ main (int argc, char *const *argv)
       return 77;
     }
 
-  if (setup_ca_cert () == NULL)
+  if (NULL == (crt = setup_ca_cert ()))
     {
       fprintf (stderr, MHD_E_TEST_FILE_CREAT);
       curl_global_cleanup ();
       return 99;
     }
-
+  fclose (crt);
   if (curl_uses_nss_ssl() == 0)
     {
       aes256_sha = "rsa_aes_256_sha";
diff --git a/src/testcurl/test_callback.c b/src/testcurl/test_callback.c
index 1c5e98d2..2323217b 100644
--- a/src/testcurl/test_callback.c
+++ b/src/testcurl/test_callback.c
@@ -70,10 +70,17 @@ callback(void *cls,
   struct callback_closure *cbc = calloc(1, sizeof(struct callback_closure));
   struct MHD_Response *r;
   int ret;
-  (void)cls;(void)url;                          /* Unused. Silent compiler 
warning. */
-  (void)method;(void)version;(void)upload_data; /* Unused. Silent compiler 
warning. */
-  (void)upload_data_size;(void)con_cls;         /* Unused. Silent compiler 
warning. */
 
+  (void)cls;
+  (void)url;                          /* Unused. Silent compiler warning. */
+  (void)method;
+  (void)version;
+  (void)upload_data; /* Unused. Silent compiler warning. */
+  (void)upload_data_size;
+  (void)con_cls;         /* Unused. Silent compiler warning. */
+
+  if (NULL == cbc)
+    return MHD_NO;
   r = MHD_create_response_from_callback (MHD_SIZE_UNKNOWN, 1024,
                                         &called_twice, cbc,
                                         &free);
diff --git a/src/testcurl/test_get_chunked.c b/src/testcurl/test_get_chunked.c
index 5d48fdc0..d813566c 100644
--- a/src/testcurl/test_get_chunked.c
+++ b/src/testcurl/test_get_chunked.c
@@ -119,8 +119,11 @@ ahc_echo (void *cls,
   struct MHD_Response *response;
   struct MHD_Response **responseptr;
   int ret;
-  (void)url;(void)version;                      /* Unused. Silent compiler 
warning. */
-  (void)upload_data;(void)upload_data_size;     /* Unused. Silent compiler 
warning. */
+
+  (void)url;
+  (void)version;                      /* Unused. Silent compiler warning. */
+  (void)upload_data;
+  (void)upload_data_size;     /* Unused. Silent compiler warning. */
 
   if (0 != strcmp (me, method))
     return MHD_NO;              /* unexpected method */
diff --git a/src/testzzuf/test_get_chunked.c b/src/testzzuf/test_get_chunked.c
index e36145ea..a74b5d9f 100644
--- a/src/testzzuf/test_get_chunked.c
+++ b/src/testzzuf/test_get_chunked.c
@@ -99,8 +99,11 @@ ahc_echo (void *cls,
   struct MHD_Response *response;
   struct MHD_Response **responseptr;
   int ret;
-  (void)url;(void)version;                      /* Unused. Silent compiler 
warning. */
-  (void)upload_data;(void)upload_data_size;     /* Unused. Silent compiler 
warning. */
+
+  (void) url;
+  (void) version;                      /* Unused. Silent compiler warning. */
+  (void) upload_data;
+  (void) upload_data_size;     /* Unused. Silent compiler warning. */
 
   if (0 != strcmp (me, method))
     return MHD_NO;              /* unexpected method */
@@ -111,11 +114,20 @@ ahc_echo (void *cls,
       return MHD_YES;
     }
   responseptr = malloc (sizeof (struct MHD_Response *));
+  if (NULL == responseptr)
+    return MHD_NO;
   response = MHD_create_response_from_callback (MHD_SIZE_UNKNOWN,
                                                 1024,
                                                 &crc, responseptr, &crcf);
+  if (NULL == response)
+  {
+    free (responseptr);
+    return MHD_NO;
+  }
   *responseptr = response;
-  ret = MHD_queue_response (connection, MHD_HTTP_OK, response);
+  ret = MHD_queue_response (connection,
+                            MHD_HTTP_OK,
+                            response);
   MHD_destroy_response (response);
   return ret;
 }
diff --git a/src/testzzuf/test_long_header.c b/src/testzzuf/test_long_header.c
index fd0598f1..de35b58a 100644
--- a/src/testzzuf/test_long_header.c
+++ b/src/testzzuf/test_long_header.c
@@ -224,10 +224,11 @@ int
 main (int argc, char *const *argv)
 {
   unsigned int errorCount = 0;
-  (void)argc;   /* Unused. Silent compiler warning. */
+  (void) argc;   /* Unused. Silent compiler warning. */
+  const char *sl;
 
-  oneone = (NULL != strrchr (argv[0], (int) '/')) ?
-    (NULL != strstr (strrchr (argv[0], (int) '/'), "11")) : 0;
+  sl = strrchr (argv[0], (int) '/');
+    oneone = (NULL != sl) ? (NULL != strstr (sl), "11")) : 0;
   if (0 != curl_global_init (CURL_GLOBAL_WIN32))
     return 2;
   errorCount += testLongUrlGet ();

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

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