Patchwork [v2] support: don't pass to resolv_test_start a big struct by value

login
register
mail settings
Submitter Konstantin Kharlamov
Date March 24, 2019, 2:55 p.m.
Message ID <20190324145553.11297-1-Hi-Angel@yandex.ru>
Download mbox | patch
Permalink /patch/31968/
State New
Headers show

Comments

Konstantin Kharlamov - March 24, 2019, 2:55 p.m.
Fixes LGTM warning: "This parameter of type resolv_redirect_config is
88 bytes - consider passing a const pointer/reference instead."

v2: copy the nscount field over to "obj"

Signed-off-by: Konstantin Kharlamov <Hi-Angel@yandex.ru>
---
 support/resolv_test.c | 34 +++++++++++++++++-----------------
 support/resolv_test.h |  2 +-
 2 files changed, 18 insertions(+), 18 deletions(-)

Patch

diff --git a/support/resolv_test.c b/support/resolv_test.c
index f400026cd1..ca87070e4a 100644
--- a/support/resolv_test.c
+++ b/support/resolv_test.c
@@ -1103,44 +1103,44 @@  set_search_path (const struct resolv_redirect_config* config)
 }
 
 struct resolv_test *
-resolv_test_start (struct resolv_redirect_config config)
+resolv_test_start (const struct resolv_redirect_config *config)
 {
   /* Apply configuration defaults.  */
-  if (config.nscount == 0)
-    config.nscount = resolv_max_test_servers;
+  const int nscount = (config->nscount == 0)? resolv_max_test_servers : 0;
 
   struct resolv_test *obj = xmalloc (sizeof (*obj));
   *obj = (struct resolv_test) {
-    .config = config,
+    .config = *config,
     .lock = PTHREAD_MUTEX_INITIALIZER,
   };
+  obj->config.nscount = nscount;
 
-  if (!config.disable_redirect)
+  if (!config->disable_redirect)
     resolv_test_init ();
 
   /* Create all the servers, to reserve the necessary ports.  */
-  for (int server_index = 0; server_index < config.nscount; ++server_index)
-    if (config.disable_redirect && config.server_address_overrides != NULL)
+  for (int server_index = 0; server_index < nscount; ++server_index)
+    if (config->disable_redirect && config->server_address_overrides != NULL)
       make_server_sockets_for_address
         (obj->servers + server_index,
-         config.server_address_overrides[server_index]);
+         config->server_address_overrides[server_index]);
     else
       make_server_sockets (obj->servers + server_index);
 
   /* Start server threads.  Disable the server ports, as
      requested.  */
-  for (int server_index = 0; server_index < config.nscount; ++server_index)
+  for (int server_index = 0; server_index < nscount; ++server_index)
     {
       struct resolv_test_server *server = obj->servers + server_index;
-      if (config.servers[server_index].disable_udp)
+      if (config->servers[server_index].disable_udp)
         {
           xclose (server->socket_udp);
           server->socket_udp = -1;
         }
-      else if (!config.single_thread_udp)
+      else if (!config->single_thread_udp)
         server->thread_udp = start_server_thread (obj, server_index,
                                                   server_thread_udp);
-      if (config.servers[server_index].disable_tcp)
+      if (config->servers[server_index].disable_tcp)
         {
           xclose (server->socket_tcp);
           server->socket_tcp = -1;
@@ -1149,10 +1149,10 @@  resolv_test_start (struct resolv_redirect_config config)
         server->thread_tcp = start_server_thread (obj, server_index,
                                                   server_thread_tcp);
     }
-  if (config.single_thread_udp)
+  if (config->single_thread_udp)
     start_server_thread_udp_single (obj);
 
-  if (config.disable_redirect)
+  if (config->disable_redirect)
     return obj;
 
   int timeout = 1;
@@ -1176,7 +1176,7 @@  resolv_test_start (struct resolv_redirect_config config)
     }
   _res.retrans = timeout;
   _res.retry = 4;
-  _res.nscount = config.nscount;
+  _res.nscount = nscount;
   _res.options = RES_INIT | RES_RECURSE | RES_DEFNAMES | RES_DNSRCH;
   _res.ndots = 1;
   if (test_verbose)
@@ -1187,7 +1187,7 @@  resolv_test_start (struct resolv_redirect_config config)
       printf ("info: new _res.nscount value: %d\n", _res.nscount);
       printf ("info: new _res.ndots value: %d\n", _res.ndots);
     }
-  for (int server_index = 0; server_index < config.nscount; ++server_index)
+  for (int server_index = 0; server_index < nscount; ++server_index)
     {
       TEST_VERIFY_EXIT (obj->servers[server_index].address.sin_port != 0);
       _res.nsaddr_list[server_index] = obj->servers[server_index].address;
@@ -1203,7 +1203,7 @@  resolv_test_start (struct resolv_redirect_config config)
         }
     }
 
-  set_search_path (&config);
+  set_search_path (config);
 
   return obj;
 }
diff --git a/support/resolv_test.h b/support/resolv_test.h
index c9e48205ab..880330ad5c 100644
--- a/support/resolv_test.h
+++ b/support/resolv_test.h
@@ -116,7 +116,7 @@  void resolv_test_init (void);
    needed.  As a side effect, NSS is reconfigured to use nss_dns only
    for aplicable databases, and the process may enter a network
    namespace for better isolation.  */
-struct resolv_test *resolv_test_start (struct resolv_redirect_config);
+struct resolv_test *resolv_test_start (const struct resolv_redirect_config*);
 
 /* Call this function at the end of resolver testing, to free
    resources and report pending errors (if any).  */