From patchwork Sat Apr 23 18:24:56 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Frysinger X-Patchwork-Id: 11865 X-Patchwork-Delegate: vapier@gentoo.org Received: (qmail 81958 invoked by alias); 23 Apr 2016 18:25:01 -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 81938 invoked by uid 89); 23 Apr 2016 18:25:00 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.9 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 spammy=54, 7 X-HELO: smtp.gentoo.org Date: Sat, 23 Apr 2016 14:24:56 -0400 From: Mike Frysinger To: Florian Weimer Cc: libc-alpha@sourceware.org Subject: Re: [PATCH] tst-fmon/tst-numeric: switch malloc to static stack space [BZ #19671] Message-ID: <20160423182456.GM5369@vapier.lan> Mail-Followup-To: Florian Weimer , libc-alpha@sourceware.org References: <1461359558-26367-1-git-send-email-vapier@gentoo.org> <87inz8jyxt.fsf@mid.deneb.enyo.de> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <87inz8jyxt.fsf@mid.deneb.enyo.de> On 23 Apr 2016 14:23, Florian Weimer wrote: > * Mike Frysinger: > > The current test code doesn't check the return value of malloc. > > This should rarely (if ever) cause a problem, but rather than add > > some return value checks, just statically allocate the buffer on > > the stack. This will never fail (or if it does, we've got much > > bigger problems that don't matter to the test). > > This needs a ChangeLog entry. i don't bother writing ChangeLog entries until before i push. it helps minimize time wastage. > > - char *s = malloc (201); > > + char s[201]; > > Please use a enum constant of 200, and also pass it to strfmon. > K think the current 200/201 choice is technically incorrect > (the maximum includes the terminating null byte). these two tests are both badly written. i've changed it to sizeof. -mike From 54e15c89dbb0806a6924b0e573fc64a2a839c2fb Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Fri, 22 Apr 2016 17:11:09 -0400 Subject: [PATCH] tst-fmon/tst-numeric: switch malloc to static stack space [BZ #19671] The current test code doesn't check the return value of malloc. This should rarely (if ever) cause a problem, but rather than add some return value checks, just statically allocate the buffer on the stack. This will never fail (or if it does, we've got much bigger problems that don't matter to the test). --- localedata/tst-fmon.c | 4 ++-- localedata/tst-numeric.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/localedata/tst-fmon.c b/localedata/tst-fmon.c index 995cf90..62cd7db 100644 --- a/localedata/tst-fmon.c +++ b/localedata/tst-fmon.c @@ -40,7 +40,7 @@ int main (int argc, char *argv[]) { - char *s = malloc (201); + char s[200]; if (setlocale (LC_MONETARY, argv[1]) == NULL) { @@ -48,7 +48,7 @@ main (int argc, char *argv[]) exit (EXIT_SETLOCALE); } - if (strfmon (s, 200, argv[2], (double) atof (argv[3])) == -1) + if (strfmon (s, sizeof (s), argv[2], (double) atof (argv[3])) == -1) { perror ("strfmon"); exit (EXIT_STRFMON); diff --git a/localedata/tst-numeric.c b/localedata/tst-numeric.c index 46a6b48..64abb0a 100644 --- a/localedata/tst-numeric.c +++ b/localedata/tst-numeric.c @@ -41,7 +41,7 @@ int main (int argc, char *argv[]) { - char *s = malloc (201); + char s[200]; double val; /* Make sure to read the value before setting of the locale, as @@ -54,7 +54,7 @@ main (int argc, char *argv[]) exit (EXIT_SETLOCALE); } - if (snprintf (s, 200, argv[2], val) == -1) + if (snprintf (s, sizeof (s), argv[2], val) == -1) { perror ("snprintf"); exit (EXIT_SNPRINTF); -- 2.7.4