[v2,2/3] nss/grp: don't pass src by value to copy_grp
diff mbox series

Message ID 20190331174420.30823-3-Hi-Angel@yandex.ru
State New
Headers show
Series
  • Minor LGTM fixes
Related show

Commit Message

Konstantin Kharlamov March 31, 2019, 5:44 p.m. UTC
Fixes LGTM warning: "This parameter of type spwd is 72 bytes - consider
passing a const pointer/reference instead."

Signed-off-by: Konstantin Kharlamov <Hi-Angel@yandex.ru>
---
 grp/grp-merge.c   | 24 ++++++++++++------------
 grp/grp-merge.h   |  2 +-
 nss/getXXbyYY_r.c |  6 +++---
 3 files changed, 16 insertions(+), 16 deletions(-)

Patch
diff mbox series

diff --git a/grp/grp-merge.c b/grp/grp-merge.c
index 8227d52ea5..ad2c8cd5a5 100644
--- a/grp/grp-merge.c
+++ b/grp/grp-merge.c
@@ -36,7 +36,7 @@ 
   })
 
 int
-__copy_grp (const struct group srcgrp, const size_t buflen,
+__copy_grp (const struct group *srcgrp, const size_t buflen,
 	    struct group *destgrp, char *destbuf, char **endptr)
 {
   size_t i;
@@ -46,24 +46,24 @@  __copy_grp (const struct group srcgrp, const size_t buflen,
   char **members = NULL;
 
   /* Copy the GID.  */
-  destgrp->gr_gid = srcgrp.gr_gid;
+  destgrp->gr_gid = srcgrp->gr_gid;
 
   /* Copy the name.  */
-  len = strlen (srcgrp.gr_name) + 1;
+  len = strlen (srcgrp->gr_name) + 1;
   BUFCHECK (len);
-  memcpy (&destbuf[c], srcgrp.gr_name, len);
+  memcpy (&destbuf[c], srcgrp->gr_name, len);
   destgrp->gr_name = &destbuf[c];
   c += len;
 
   /* Copy the password.  */
-  len = strlen (srcgrp.gr_passwd) + 1;
+  len = strlen (srcgrp->gr_passwd) + 1;
   BUFCHECK (len);
-  memcpy (&destbuf[c], srcgrp.gr_passwd, len);
+  memcpy (&destbuf[c], srcgrp->gr_passwd, len);
   destgrp->gr_passwd = &destbuf[c];
   c += len;
 
   /* Count all of the members.  */
-  for (memcount = 0; srcgrp.gr_mem[memcount]; memcount++)
+  for (memcount = 0; srcgrp->gr_mem[memcount]; memcount++)
     ;
 
   /* Allocate a temporary holding area for the pointers to the member
@@ -74,11 +74,11 @@  __copy_grp (const struct group srcgrp, const size_t buflen,
 
   /* Copy all of the group members to destbuf and add a pointer to each of
      them into the 'members' array.  */
-  for (i = 0; srcgrp.gr_mem[i]; i++)
+  for (i = 0; srcgrp->gr_mem[i]; i++)
     {
-      len = strlen (srcgrp.gr_mem[i]) + 1;
+      len = strlen (srcgrp->gr_mem[i]) + 1;
       BUFCHECK (len);
-      memcpy (&destbuf[c], srcgrp.gr_mem[i], len);
+      memcpy (&destbuf[c], srcgrp->gr_mem[i], len);
       members[i] = &destbuf[c];
       c += len;
     }
@@ -131,7 +131,7 @@  __merge_grp (struct group *savedgrp, char *savedbuf, char *savedend,
      treating the new lookup as NSS_STATUS_NOTFOUND).  */
   if (mergegrp->gr_gid != savedgrp->gr_gid
       || strcmp (mergegrp->gr_name, savedgrp->gr_name))
-    return __copy_grp (*savedgrp, buflen, mergegrp, mergebuf, NULL);
+    return __copy_grp (savedgrp, buflen, mergegrp, mergebuf, NULL);
 
   /* Get the count of group members from the last sizeof (size_t) bytes in the
      mergegrp buffer.  */
@@ -195,6 +195,6 @@  __merge_grp (struct group *savedgrp, char *savedbuf, char *savedend,
 
   /* Finally, copy the results back into mergebuf, since that's the buffer
      that we were provided by the caller.  */
-  return __copy_grp (*savedgrp, buflen, mergegrp, mergebuf, NULL);
+  return __copy_grp (savedgrp, buflen, mergegrp, mergebuf, NULL);
 }
 libc_hidden_def (__merge_grp)
diff --git a/grp/grp-merge.h b/grp/grp-merge.h
index d483ea2bf1..46dcdae5de 100644
--- a/grp/grp-merge.h
+++ b/grp/grp-merge.h
@@ -24,7 +24,7 @@ 
 /* Duplicate a grp struct (and its members). When no longer needed, the
    calling function must free(newbuf).  */
 int
-__copy_grp (const struct group srcgrp, const size_t buflen,
+__copy_grp (const struct group *srcgrp, const size_t buflen,
 	    struct group *destgrp, char *destbuf, char **endptr);
 
 /* Merge the member lists of two grp structs together.  */
diff --git a/nss/getXXbyYY_r.c b/nss/getXXbyYY_r.c
index cf867210fc..4b8d5e6d08 100644
--- a/nss/getXXbyYY_r.c
+++ b/nss/getXXbyYY_r.c
@@ -131,7 +131,7 @@ 
 /* Set defaults for merge functions that haven't been defined.  */
 #ifndef DEEPCOPY_FN
 static inline int
-__copy_einval (LOOKUP_TYPE a,
+__copy_einval (const LOOKUP_TYPE *a,
 	       const size_t b,
 	       LOOKUP_TYPE *c,
 	       char *d,
@@ -351,7 +351,7 @@  INTERNAL (REENTRANT_NAME) (ADD_PARAMS, LOOKUP_TYPE *resbuf, char *buffer,
 	            acquired values.
 	          * If the next action is MERGE, then it will be added to the
 	            buffer saved from the previous source.  */
-	      err = DEEPCOPY_FN (mergegrp, buflen, resbuf, buffer, NULL);
+	      err = DEEPCOPY_FN (&mergegrp, buflen, resbuf, buffer, NULL);
 	      CHECK_MERGE (err, status);
 	      status = NSS_STATUS_SUCCESS;
 	    }
@@ -377,7 +377,7 @@  INTERNAL (REENTRANT_NAME) (ADD_PARAMS, LOOKUP_TYPE *resbuf, char *buffer,
 		}
 	    }
 
-	  err = DEEPCOPY_FN (*resbuf, buflen, &mergegrp, mergebuf, &endptr);
+	  err = DEEPCOPY_FN (resbuf, buflen, &mergegrp, mergebuf, &endptr);
 	  CHECK_MERGE (err, status);
 	  do_merge = 1;
 	}