1 From 12846e741d925630a4079ac02290b28c6f00b887 Mon Sep 17 00:00:00 2001
2 From: Nathan Sidwell <nathan@codesourcery.com>
3 Date: Fri, 22 Mar 2013 17:46:52 +0100
4 Subject: [PATCH] Fix a problem with scanning wide chars.
6 We found that the testcase
12 memset (s, 0, sizeof (s));
13 int r = sscanf ("s", "%ls", s);
23 rather than the expected
27 The problem was the enum in _scanf.c, which has had a 'CONV_m' value
28 inserted. The attached patch fixes the problem in __psfs_parse_spec by
29 not presuming a particular displacement between the two sets of
30 char-like conversion values. With this patch the above program produces
33 Signed-off-by: Nathan Sidwell <nathan@codesourcery.com>
34 Signed-off-by: Bernd Schmidt <bernds@codesourcery.com>
35 Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
37 libc/stdio/_scanf.c | 6 +++---
38 1 file changed, 3 insertions(+), 3 deletions(-)
40 diff --git a/libc/stdio/_scanf.c b/libc/stdio/_scanf.c
41 index 952853c..3848a09 100644
42 --- a/libc/stdio/_scanf.c
43 +++ b/libc/stdio/_scanf.c
44 @@ -429,8 +429,8 @@ libc_hidden_def(vswscanf)
45 /* npxXoudif eEgG CS cs[ */
46 /* NOTE: the 'm' flag must come before any convs that support it */
48 -/* NOTE: Ordering is important! In particular, CONV_LEFTBRACKET
49 - * must immediately precede CONV_c. */
50 +/* NOTE: Ordering is important! The CONV_{C,S,LEFTBRACKET} must map
51 + simply to their lowercase equivalents. */
55 @@ -921,7 +921,7 @@ int attribute_hidden __psfs_parse_spec(register psfs_t *psfs)
56 psfs->dataargtype = PA_FLAG_LONG;
57 } else if ((p_m_spec_chars >= CONV_c)
58 && (psfs->dataargtype & PA_FLAG_LONG)) {
59 - p_m_spec_chars -= 3; /* lc -> C, ls -> S, l[ -> ?? */
60 + p_m_spec_chars -= CONV_c - CONV_C; /* lc -> C, ls -> S, l[ -> ?? */
63 psfs->conv_num = p_m_spec_chars;