Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix libio/bug-ungetwc1.c warning.
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.

	* libio/bug-ungetwc1.c (do_test): Verify results of getwc and
	feof.
  • Loading branch information
Joseph Myers committed Nov 27, 2014
1 parent 9114625 commit 49051f8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
3 changes: 3 additions & 0 deletions ChangeLog
@@ -1,5 +1,8 @@
2014-11-27 Joseph Myers <joseph@codesourcery.com>

* libio/bug-ungetwc1.c (do_test): Verify results of getwc and
feof.

* dlfcn/failtestmod.c (constr): Do not store result of dlsym in a
variable.

Expand Down
21 changes: 19 additions & 2 deletions libio/bug-ungetwc1.c
Expand Up @@ -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. */
Expand All @@ -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");

Expand Down

0 comments on commit 49051f8

Please sign in to comment.