From patchwork Mon Jun 19 16:22:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 21107 Received: (qmail 97674 invoked by alias); 19 Jun 2017 16:22:36 -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 97601 invoked by uid 89); 19 Jun 2017 16:22:36 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy=Hx-languages-length:1599 X-HELO: mx1.redhat.com DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 22175C04B936 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=fweimer@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 22175C04B936 Date: Mon, 19 Jun 2017 18:22:36 +0200 To: libc-alpha@sourceware.org Subject: [PATCH] _i18n_number_rewrite: Use struct scratch_buffer User-Agent: Heirloom mailx 12.5 7/5/10 MIME-Version: 1.0 Message-Id: <20170619162236.49362402AEC3C@oldenburg.str.redhat.com> From: fweimer@redhat.com (Florian Weimer) 2017-06-19 Florian Weimer * stdio-common/_i18n_number.h (_i18n_number_rewrite): Use struct scratch_buffer. diff --git a/stdio-common/_i18n_number.h b/stdio-common/_i18n_number.h index 080e814..13d5936 100644 --- a/stdio-common/_i18n_number.h +++ b/stdio-common/_i18n_number.h @@ -19,6 +19,7 @@ #include #include #include +#include #include "../locale/outdigits.h" #include "../locale/outdigitswc.h" @@ -65,17 +66,13 @@ _i18n_number_rewrite (CHAR_T *w, CHAR_T *rear_ptr, CHAR_T *end) /* Copy existing string so that nothing gets overwritten. */ CHAR_T *src; - bool use_alloca = __libc_use_alloca ((rear_ptr - w) * sizeof (CHAR_T)); - if (__builtin_expect (use_alloca, true)) - src = (CHAR_T *) alloca ((rear_ptr - w) * sizeof (CHAR_T)); - else - { - src = (CHAR_T *) malloc ((rear_ptr - w) * sizeof (CHAR_T)); - if (src == NULL) - /* If we cannot allocate the memory don't rewrite the string. - It is better than nothing. */ - return w; - } + struct scratch_buffer buffer; + scratch_buffer_init (&buffer); + if (!scratch_buffer_set_array_size (&buffer, rear_ptr - w, sizeof (CHAR_T))) + /* If we cannot allocate the memory don't rewrite the string. + It is better than nothing. */ + return w; + src = buffer.data; CHAR_T *s = (CHAR_T *) __mempcpy (src, w, (rear_ptr - w) * sizeof (CHAR_T)); @@ -110,8 +107,6 @@ _i18n_number_rewrite (CHAR_T *w, CHAR_T *rear_ptr, CHAR_T *end) } } - if (! use_alloca) - free (src); - + scratch_buffer_free (&buffer); return w; }