From patchwork Wed Apr 3 00:08:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: DJ Delorie X-Patchwork-Id: 32133 Received: (qmail 97212 invoked by alias); 3 Apr 2019 00:08:32 -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 97204 invoked by uid 89); 3 Apr 2019 00:08:32 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-17.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=shut, yup, alternatives, HTo:D*marvell.com X-HELO: mx1.redhat.com From: DJ Delorie To: Steve Ellcey Cc: libc-alpha@sourceware.org, tamuki@linet.gr.jp, digitalfreak@lingonborough.com Subject: Re: [v1] Add Reiwa era tests to time/tst-strftime3.c In-Reply-To: (message from Steve Ellcey on Tue, 2 Apr 2019 22:36:52 +0000) Date: Tue, 02 Apr 2019 20:08:17 -0400 Message-ID: MIME-Version: 1.0 Steve Ellcey writes: > I am building ToT glibc with ToT gcc and during glibc testing I got > this error: Yup, Arjun noticed as well when trying in Rawhide. It's a wierd warning, too, because the *point* of snprintf is that it truncates the output. Arjun and I talked about a few options, but I think the simplest is to just shut gcc up... alternatives include far bigger buffers with sprintf, or xasprintf... but what's the point of snprintf at all then? diff --git a/time/tst-strftime3.c b/time/tst-strftime3.c index 32ce0d93e2..2a4c3ea398 100644 --- a/time/tst-strftime3.c +++ b/time/tst-strftime3.c @@ -430,16 +430,21 @@ static void tm_to_printed (struct tm *tm, char *buffer) { const char *wn; - char temp[50]; + char temp[28]; if (0 <= tm->tm_wday && tm->tm_wday <= 6) wn = weekday_name[tm->tm_wday]; else { wn = temp; + /* 64-bit values need at most 21 bytes, including NUL. */ sprintf (temp, "%d", tm->tm_wday); } + /* This will be at most 4+2+2+2+2+2+7+20 = 41 bytes long, including + NUL. GCC warns if snprintf may truncate the output, which is why + we're using snprintf... */ +#pragma GCC diagnostic ignored "-Wformat-truncation=" snprintf (buffer, TMBUFLEN, "%04d/%02d/%02d %02d:%02d:%02d %s", tm->tm_year + 1900, tm->tm_mon + 1,