From patchwork Wed Dec 10 15:13:34 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?T25kxZllaiBCw61sa2E=?= X-Patchwork-Id: 419704 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id CD4E21400DE for ; Thu, 11 Dec 2014 02:21:58 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:cc:subject:message-id:references :mime-version:content-type:content-transfer-encoding :in-reply-to; q=dns; s=default; b=fCcSTGpawNo7NOFGtzbnGPk6OO4RsC 8ryU+U05536hHyOEtawGZEcJbKgMXkjx5YoYssCPeOd+myXEcJsAFIWX2EMDr5z6 t1F4Yn5DPIZt64+5m1IC4mrbpdKgWxSyz1DbFu5gZLq/KuDxGwWhsNWJZfuY4Ie0 zfevtFtMny5cw= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:cc:subject:message-id:references :mime-version:content-type:content-transfer-encoding :in-reply-to; s=default; bh=o2zU6/XY9STL2XqwwU9TsHNjw0M=; b=pSLv GcWJBafFFCkNvjqkVfLNjtQlW9+2xt3XVHFmzCOgnj8v3fDtBspCOxuUpvFDBLPu IokqfefezqoUpZpwX7jdjZdYLc1Q4SgscwLSVFyoS1Ll9RTQutCxzY3YC9RJcTHR 2v1rjBqvmKinGxqiN/5bIU1wfAvStddceViWkRA= Received: (qmail 30335 invoked by alias); 10 Dec 2014 15:13:49 -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 30325 invoked by uid 89); 10 Dec 2014 15:13:49 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.7 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, SPF_NEUTRAL autolearn=no version=3.3.2 X-HELO: popelka.ms.mff.cuni.cz Date: Wed, 10 Dec 2014 16:13:34 +0100 From: =?utf-8?B?T25kxZllaiBCw61sa2E=?= To: Andreas Schwab Cc: libc-alpha@sourceware.org Subject: Re: [PATCH][BZ #17657] Return allocated array instead array on stack. Message-ID: <20141210151334.GA27824@domone> References: <20141210132153.GA6395@domone> <20141210143252.GA27265@domone> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.20 (2009-06-14) On Wed, Dec 10, 2014 at 03:50:53PM +0100, Andreas Schwab wrote: > Ondřej Bílka writes: > > > On Wed, Dec 10, 2014 at 03:09:53PM +0100, Andreas Schwab wrote: > >> Ondřej Bílka writes: > >> > >> > here we return array on stack which is invalid. OK to fix it in obvious way? > >> > >> The obvious way would be a static allocation. > >> > > which breaks when user modifies array. > > Which user? > I meant caller, as I looked at code more caller cannot modify it so static allocation is ok. Also found second occurence of same problem. [BZ #17657] * locale/programs/ld-ctype.c (find_translit2, read_widestring): Return static array. diff --git a/locale/programs/ld-ctype.c b/locale/programs/ld-ctype.c index 67846b3..eeaf645 100644 --- a/locale/programs/ld-ctype.c +++ b/locale/programs/ld-ctype.c @@ -114,6 +114,9 @@ struct translit_include_t struct translit_include_t *next; }; +/* Provide some dummy pointer for empty string. */ +static uint32_t no_str[] = { 0 }; + /* Sparse table of uint32_t. */ #define TABLE idx_table @@ -1777,7 +1780,7 @@ find_translit2 (struct locale_ctype_t *ctype, const struct charmap_t *charmap, for (wi = tirunp->from; wi <= wch; wi += tirunp->step) if (wi == wch) - return (uint32_t []) { 0 }; + return no_str; } } @@ -1831,7 +1834,7 @@ read_widestring (struct linereader *ldfile, struct token *now, if (now->tok == tok_default_missing) /* The special name "" will denote this case. */ - wstr = ((uint32_t *) { 0 }); + wstr = no_str; else if (now->tok == tok_bsymbol) { /* Get the value from the repertoire. */ @@ -4090,9 +4093,6 @@ allocate_arrays (struct locale_ctype_t *ctype, const struct charmap_t *charmap, } else { - /* Provide some dummy pointers since we have nothing to write out. */ - static uint32_t no_str = { 0 }; - ctype->translit_from_idx = &no_str; ctype->translit_from_tbl = &no_str; ctype->translit_to_tbl = &no_str;