diff mbox

nscd_getgr_r: Replace scratch buffer with dynamic array

Message ID 20170602120012.F3D7F401268B1@oldenburg.str.redhat.com
State New, archived
Headers show

Commit Message

Florian Weimer June 2, 2017, noon UTC
2017-06-02  Florian Weimer  <fweimer@redhat.com>

	* nscd/nscd_getgr_r.c (struct grouplen_array): Define using
	<malloc/dynarray.h>.
	(nscd_getgr_r): Use it instead of struct scratch_buffer.
diff mbox

Patch

diff --git a/nscd/nscd_getgr_r.c b/nscd/nscd_getgr_r.c
index 87b4552..6ed51be 100644
--- a/nscd/nscd_getgr_r.c
+++ b/nscd/nscd_getgr_r.c
@@ -31,7 +31,6 @@ 
 #include <sys/un.h>
 #include <not-cancel.h>
 #include <_itoa.h>
-#include <scratch_buffer.h>
 
 #include "nscd-client.h"
 #include "nscd_proto.h"
@@ -80,6 +79,10 @@  libc_freeres_fn (gr_map_free)
     }
 }
 
+#define DYNARRAY_STRUCT grouplen_array
+#define DYNARRAY_ELEMENT uint32_t
+#define DYNARRAY_PREFIX grouplen_array_
+#include <malloc/dynarray-skeleton.c>
 
 static int
 internal_function
@@ -90,8 +93,8 @@  nscd_getgr_r (const char *key, size_t keylen, request_type type,
   int gc_cycle;
   int nretries = 0;
   const uint32_t *len = NULL;
-  struct scratch_buffer lenbuf;
-  scratch_buffer_init (&lenbuf);
+  struct grouplen_array lenarray;
+  grouplen_array_init (&lenarray);
 
   /* If the mapping is available, try to search there instead of
      communicating with the nscd.  */
@@ -202,10 +205,9 @@  nscd_getgr_r (const char *key, size_t keylen, request_type type,
 	  else
 	    {
 	      /* Allocate array to store lengths.  */
-	      if (!scratch_buffer_set_array_size
-		  (&lenbuf, gr_resp.gr_mem_cnt, sizeof (uint32_t)))
+	      if (!grouplen_array_resize (&lenarray, gr_resp.gr_mem_cnt))
 		goto out_close;
-	      len = lenbuf.data;
+	      len = grouplen_array_at (&lenarray, 0);
 
 	      vec[0].iov_base = (void *) len;
 	      vec[0].iov_len = gr_resp.gr_mem_cnt * sizeof (uint32_t);
@@ -324,7 +326,7 @@  nscd_getgr_r (const char *key, size_t keylen, request_type type,
 	goto retry;
     }
 
-  scratch_buffer_free (&lenbuf);
+  grouplen_array_free (&lenarray);
 
   return retval;
 }