From patchwork Fri Jun 2 12:00:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 20695 Received: (qmail 91643 invoked by alias); 2 Jun 2017 12:00:58 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 90913 invoked by uid 89); 2 Jun 2017 12:00:24 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RP_MATCHES_RCVD, SPF_HELO_PASS, UNWANTED_LANGUAGE_BODY autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 07CB633458E 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@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 07CB633458E Date: Fri, 02 Jun 2017 14:00:12 +0200 To: libc-alpha@sourceware.org Subject: [PATCH] nscd_getgr_r: Replace scratch buffer with dynamic array User-Agent: Heirloom mailx 12.5 7/5/10 MIME-Version: 1.0 Message-Id: <20170602120012.F3D7F401268B1@oldenburg.str.redhat.com> From: fweimer@redhat.com (Florian Weimer) 2017-06-02 Florian Weimer * nscd/nscd_getgr_r.c (struct grouplen_array): Define using . (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 #include #include <_itoa.h> -#include #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 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; }