This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH] nscd_getgr_r: Replace scratch buffer with dynamic array
- From: fweimer at redhat dot com (Florian Weimer)
- To: libc-alpha at sourceware dot org
- Date: Fri, 02 Jun 2017 14:00:12 +0200
- Subject: [PATCH] nscd_getgr_r: Replace scratch buffer with dynamic array
- Authentication-results: sourceware.org; auth=none
- Authentication-results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com
- Authentication-results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=fweimer at redhat dot com
- Dkim-filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 07CB633458E
- Dmarc-filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 07CB633458E
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 --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;
}