Forwarding from Nathan who's not subscribed. Ok for me to commit this patch?

Bernd


Hi,

we found a problem with scanning wide chars.  for example the following
program:

#include <stddef.h>
#include <stdio.h>

int
main (void)
{
  wchar_t s[10];
  memset (s, 0, sizeof (s));
  int r = sscanf ("s", "%ls", s);
  printf ("%d\n", r);
  printf ("%ls\n", s);
  return 0;
}

printed
0
<blankline>

rather than the expected
1
s

The problem was the enum in _scanf.c, which has had a 'CONV_m' value
inserted. The attached patch fixes the problem in __psfs_parse_spec by
not presuming a particular displacement between the two sets of
char-like conversion values. With this patch the above program produces
the expected output.

nathan

-- 
Nathan Sidwell

2013-03-19  Nathan Sidwell  <nat...@codesourcery.com>

        * libc/stdio/_scanf.c: Update comment on CONV enum ordering.
        (__psfs_parse_spec): Adjust char-like conv mapping code.

Index: libc/stdio/_scanf.c
===================================================================
--- libc/stdio/_scanf.c (revision 404962)
+++ libc/stdio/_scanf.c (working copy)
@@ -429,8 +429,8 @@ libc_hidden_def(vswscanf)
 /*                       npxXoudif eEgG  CS  cs[ */
 /* NOTE: the 'm' flag must come before any convs that support it */

-/* NOTE: Ordering is important!  In particular, CONV_LEFTBRACKET
- * must immediately precede CONV_c. */
+/* NOTE: Ordering is important!  The CONV_{C,S,LEFTBRACKET} must map
+   simply to their lowercase equivalents.  */

 enum {
        CONV_n = 0,
@@ -921,7 +921,7 @@ int attribute_hidden __psfs_parse_spec(r
                                psfs->dataargtype = PA_FLAG_LONG;
                        } else if ((p_m_spec_chars >= CONV_c)
                                && (psfs->dataargtype & PA_FLAG_LONG)) {
-                               p_m_spec_chars -= 3; /* lc -> C, ls -> S, l[ -> 
?? */
+                               p_m_spec_chars -= CONV_c - CONV_C; /* lc -> C, 
ls -> S, l[ -> ?? */
                        }

                        psfs->conv_num = p_m_spec_chars;

_______________________________________________
uClibc mailing list
uClibc@uclibc.org
http://lists.busybox.net/mailman/listinfo/uclibc

Reply via email to