bin/75638: sscanf %lld broken on 4.x
Pawel Malachowski
pawmal-posting at freebsd.lublin.pl
Wed Dec 29 15:00:47 PST 2004
>Number: 75638
>Category: bin
>Synopsis: sscanf %lld broken on 4.x
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: freebsd-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: sw-bug
>Submitter-Id: current-users
>Arrival-Date: Wed Dec 29 23:00:46 GMT 2004
>Closed-Date:
>Last-Modified:
>Originator: Pawe³ Ma³achowski
>Release: FreeBSD 4.11-STABLE i386
>Organization:
ZiN
>Environment:
System: FreeBSD 4.11-STABLE #20: Sat Dec 18 19:32:41 CET 2004
>Description:
sscanf(s, "%lld", &l) will not set l to valid value if l was previously
not zero.
For example, ports/net-mgmt/iftop `max-bandwidth' option is broken on 4.x because of this.
>How-To-Repeat:
#include <stdio.h>
void main(void) {
char *s = "10";
long long l;
int rc = 0;
rc = sscanf(s, "%lld", &l);
fprintf(stderr, "rc %d, s %s, l %lld\n", rc, s, l);
}
output on 4.x:
rc 1, s 10, l -4629710020483743734
output on 5.3:
rc 1, s 10, l 10
>Fix:
Workaround: set lld value to zero before using it with sscanf (noticed by venglin).
#include <stdio.h>
void main(void) {
char *s = "10";
long long l = 0;
int rc = 0;
rc = sscanf(s, "%lld", &l);
fprintf(stderr, "rc %d, s %s, l %lld\n", rc, s, l);
}
output on 4.x:
rc 1, s 10, l 10
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the freebsd-bugs
mailing list