From patchwork Wed Apr 3 21:55:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: DJ Delorie X-Patchwork-Id: 32154 Received: (qmail 77816 invoked by alias); 3 Apr 2019 21:55:19 -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 77806 invoked by uid 89); 3 Apr 2019 21:55:19 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-17.5 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=datas, corrupted 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: Wed, 03 Apr 2019 17:55:15 -0400 Message-ID: MIME-Version: 1.0 Steve Ellcey writes: > tst-strftime3.c:443:62: error: ā€˜%sā€™ directive output may be truncated writing up to 49 bytes into a region of size between 0 and 30 [-Werror=format-truncation=] Fixed thusly: snprintf will only truncate the output if the data its given is corrupted, but a truncated buffer will not match the "pristine" data's buffer, which is all we need. So just disable the warning via the DIAG macros. 2019-04-03 DJ Delorie * time/tst-strftime3.c (tm_to_printed): Disable warning about snprintf truncating output. diff --git a/time/tst-strftime3.c b/time/tst-strftime3.c index 32ce0d93e2..eeca0921cb 100644 --- a/time/tst-strftime3.c +++ b/time/tst-strftime3.c @@ -25,6 +25,7 @@ #include #include +#include /* These exist for the convenience of writing the test data, because zero-based vs one-based. */ @@ -440,6 +441,14 @@ tm_to_printed (struct tm *tm, char *buffer) sprintf (temp, "%d", tm->tm_wday); } + DIAG_PUSH_NEEDS_COMMENT; +#if __GNUC_PREREQ (9, 0) + /* GCC 9 warns that strncmp may truncate its output, but that's why + we're using it. When it needs to truncate, it got corrupted + data, and we only care that the string is different than valid + data, which won't truncate. */ + DIAG_IGNORE_NEEDS_COMMENT (9, "-Wformat-truncation="); +#endif snprintf (buffer, TMBUFLEN, "%04d/%02d/%02d %02d:%02d:%02d %s", tm->tm_year + 1900, tm->tm_mon + 1, @@ -448,6 +457,7 @@ tm_to_printed (struct tm *tm, char *buffer) tm->tm_min, tm->tm_sec, wn); + DIAG_POP_NEEDS_COMMENT; } static int