public inbox for libc-hacker@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Fix *scanf
@ 2004-04-19 22:19 Jakub Jelinek
  2004-04-20  4:19 ` Ulrich Drepper
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2004-04-19 22:19 UTC (permalink / raw)
  To: Ulrich Drepper; +Cc: Glibc hackers

Hi!

I'm not 100% sure this is correct, but certainly this patch
makes tst-sscanf behave like on Solaris.
The second hunk makes sure "x%%y" doesn't match "x       %y"
and the first causes input_error if EOF is seen while skipping
whitespace.

2004-04-20  Jakub Jelinek  <jakub@redhat.com>

	* stdio-common/vfscanf.c (_IO_vfscanf): When skipping whitespace,
	do input_error () instead of conv_error () and don't look at errno.
	Don't eat any whitespace before %% if skip_space == 0.
	* stdio-common/tst-sscanf.c (int_tests): New array.
	(main): Run int_tests.

--- libc/stdio-common/vfscanf.c.jj	2004-04-19 23:31:19.613093185 +0200
+++ libc/stdio-common/vfscanf.c	2004-04-19 23:56:25.808163418 +0200
@@ -396,8 +396,8 @@ _IO_vfscanf (s, format, argptr, errp)
 	  if (skip_space)
 	    {
 	      while (ISSPACE (c))
-		if (inchar () == EOF && errno == EINTR)
-		  conv_error ();
+		if (inchar () == EOF)
+		  input_error ();
 	      skip_space = 0;
 	    }
 
@@ -543,7 +543,8 @@ _IO_vfscanf (s, format, argptr, errp)
       /* Find the conversion specifier.  */
       fc = *f++;
       if (skip_space || (fc != L_('[') && fc != L_('c')
-			 && fc != L_('C') && fc != L_('n')))
+			 && fc != L_('C') && fc != L_('n')
+			 && fc != L_('%')))
 	{
 	  /* Eat whitespace.  */
 	  int save_errno = errno;
--- libc/stdio-common/tst-sscanf.c.jj	2002-10-11 12:55:27.000000000 +0200
+++ libc/stdio-common/tst-sscanf.c	2004-04-19 23:58:39.702167869 +0200
@@ -1,4 +1,4 @@
-/* Copyright (C) 2000, 2002 Free Software Foundation, Inc.
+/* Copyright (C) 2000, 2002, 2004 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Jakub Jelinek <jakub@redhat.com>, 2000.
 
@@ -59,6 +59,39 @@ const long int val_long[] =
   -12345678, 987654321, 123456789, 987654321, 123456789, 987654321
 };
 
+struct int_test
+{
+  const char *str;
+  const char *fmt;
+  int retval;
+} int_tests[] = 
+{
+  { "foo\n", "foo\nbar", -1 },
+  { "foo\n", "foo bar", -1 },
+  { "foo\n", "foo %d", -1 },
+  { "foo\n", "foo\n%d", -1 },
+  { "foon", "foonbar", -1 },
+  { "foon", "foon%d", -1 },
+  { "foo ", "foo bar", -1 },
+  { "foo ", "foo %d", -1 },
+  { "foo\t", "foo\tbar", -1 },
+  { "foo\t", "foo bar", -1 },
+  { "foo\t", "foo %d", -1 },
+  { "foo\t", "foo\t%d", -1 },
+  { "foo \t %bar1", "foo%%bar%d", 0 },
+  { "foo", "foo", 0 },
+  { "foon", "foo bar", 0 },
+  { "foon", "foo %d", 0 },
+  { "foo ", "fooxbar", 0 },
+  { "foo ", "foox%d", 0 },
+  { "foo bar", "foon", 0 },
+  { "foo bar", "foo bar", 0 },
+  { "foo bar", "foo %d", 0 },
+  { "foo bar", "foon%d", 0 },
+  { "foo ", "foo %n", 0 },
+  { "foo%bar1", "foo%%bar%d", 1 }
+};
+
 int
 main (void)
 {
@@ -119,5 +152,18 @@ main (void)
 	break;
     }
 
+  for (i = 0; i < sizeof (int_tests) / sizeof (int_tests[0]); ++i)
+    {
+      int dummy, ret;
+
+      if ((ret = sscanf (int_tests[i].str, int_tests[i].fmt,
+			 &dummy)) != int_tests[i].retval)
+	{
+	  printf ("int_tests[%d] returned %d != %d\n",
+		  i, ret, int_tests[i].retval);
+	  result = 1;
+	}
+    }
+
   return result;
 }

	Jakub

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Fix *scanf
  2004-04-19 22:19 [PATCH] Fix *scanf Jakub Jelinek
@ 2004-04-20  4:19 ` Ulrich Drepper
  0 siblings, 0 replies; 2+ messages in thread
From: Ulrich Drepper @ 2004-04-20  4:19 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Glibc hackers

Applied.

-- 
➧ Ulrich Drepper ➧ Red Hat, Inc. ➧ 444 Castro St ➧ Mountain View, CA ❖

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2004-04-20  4:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-04-19 22:19 [PATCH] Fix *scanf Jakub Jelinek
2004-04-20  4:19 ` Ulrich Drepper

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).