From patchwork Wed Nov 26 18:26:01 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joseph Myers X-Patchwork-Id: 3953 Received: (qmail 25711 invoked by alias); 26 Nov 2014 18:26:08 -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 25700 invoked by uid 89); 26 Nov 2014 18:26:07 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 X-HELO: relay1.mentorg.com Date: Wed, 26 Nov 2014 18:26:01 +0000 From: Joseph Myers To: Subject: Fix libio/bug-ungetwc1.c warning Message-ID: User-Agent: Alpine 2.10 (DEB 1266 2009-07-14) MIME-Version: 1.0 This patch fixes a warning "variable 'wc' set but not used" in libio/bug-ungetwc1.c. The test didn't verify much about the results of the functions it called. This patch makes it check the result of getwc (thereby fixing the warning), check end of file does not arrive too late in the getwc loop, and check EOF is no longer set after ungetwc. Tested for x86_64. 2014-11-26 Joseph Myers * libio/bug-ungetwc1.c (do_test): Verify results of getwc and feof. diff --git a/libio/bug-ungetwc1.c b/libio/bug-ungetwc1.c index 8ed6acd..56a3d33 100644 --- a/libio/bug-ungetwc1.c +++ b/libio/bug-ungetwc1.c @@ -53,8 +53,22 @@ do_test (void) /* Read from the file. */ fp = fopen (fname, "r"); + size_t i = 0; while (!feof (fp)) - wc = getwc (fp); + { + wc = getwc (fp); + if (i >= sizeof (write_chars)) + { + printf ("Did not get end-of-file when expected.\n"); + return 1; + } + else if (wc != (write_chars[i] ? write_chars[i] : WEOF)) + { + printf ("Unexpected %lu from getwc.\n", (unsigned long int) wc); + return 1; + } + i++; + } printf ("\nThe end-of-file indicator is set.\n"); /* Unget a wide character. */ @@ -63,7 +77,10 @@ do_test (void) /* Check the end-of-file indicator. */ if (feof (fp)) - printf ("The end-of-file indicator is still set.\n"); + { + printf ("The end-of-file indicator is still set.\n"); + return 1; + } else printf ("The end-of-file flag is cleared.\n");