提交 8fccae2c 编写于 作者: A Andy Spencer 提交者: Linus Torvalds

sscanf(): fix %*s%n

When using %*s, sscanf should honor conversion specifiers immediately
following the %*s.  For example, the following code should find the
position of the end of the string "hello".

  int end;
  char buf[] = "hello    world";
  sscanf(buf, "%*s%n", &end);
  printf("%d\n", end);

Ideally, sscanf would advance the fmt and str pointers the same as it
would without the *, but the code for that is rather complicated and is
not included in the patch.
Signed-off-by: NAndy Spencer <andy753421@gmail.com>
Acked-by: NWANG Cong <xiyou.wangcong@gmail.com>
Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
上级 d41a4b51
...@@ -1771,7 +1771,7 @@ int vsscanf(const char * buf, const char * fmt, va_list args) ...@@ -1771,7 +1771,7 @@ int vsscanf(const char * buf, const char * fmt, va_list args)
* advance both strings to next white space * advance both strings to next white space
*/ */
if (*fmt == '*') { if (*fmt == '*') {
while (!isspace(*fmt) && *fmt) while (!isspace(*fmt) && *fmt != '%' && *fmt)
fmt++; fmt++;
while (!isspace(*str) && *str) while (!isspace(*str) && *str)
str++; str++;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册