Subject: lib/4838: scanf(3) doesn't skip whitespace properly
To: None <>
From: None <>
List: netbsd-bugs
Date: 01/18/1998 23:58:57
>Number:         4838
>Category:       lib
>Synopsis:       scanf(3) doesn't skip whitespace properly
>Confidential:   yes
>Severity:       non-critical
>Priority:       medium
>Responsible:    lib-bug-people (Library Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Jan 18 05:35:01 1998
>Originator:     Ian Dall
>Release:        1.3
System: NetBSD 1.3_BETA NetBSD 1.3_BETA (SIBYL) #0: Sat Dec 20 01:17:57 CST 1997 pc532

According to scanf(3), blank space in a scan pattern means skip any
amount of white space *including zero*. With the pattern "%d %n" the
white space does not match zero white space.


The folowing program prints 999 characters processed instead of 3.

int main(void)
  int ret, i, n=999;
  ret = sscanf("123","%d %n", &i, &n);
  printf("%d conversions = %d, %d chars processed\n", ret, i, n);