Subject: lib/21691: sscanf(3) %i format does not work properly with -ve hex numbers
To: None <>
From: None <>
List: netbsd-bugs
Date: 05/26/2003 14:11:26
>Number:         21691
>Category:       lib
>Synopsis:       sscanf(3) %i format does not work properly with -ve hex numbers
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon May 26 21:12:00 UTC 2003
>Originator:     Jason R Thorpe
>Release:        NetBSD 1.6T
Wasabi Systems, Inc.
System: NetBSD 1.6T NetBSD 1.6T (SWINGER) #230: Tue May 13 10:28:44 PDT 2003 i386
Architecture: i386
Machine: i386
	ISO C says about sscanf()'s %i format:

	i	Matches an optionally signed integer, whose format is the
		same as expected for the subject sequence of the strtol()
		function with the value 0 for the base argument.  The
		corresponding argument shall be a pointer to a signed integer.

	Our sscanf() does not function properly.  When it encounters a
	"-0x..." number, it stops parsing after first 0, advancing the
	input pointer to the x.

	strtol() appears functions properly; this must be a problem with
	__svfscanf_unlocked()'s checking of the input stream before it
	calls the conversion function.

	Run the following test program.

#include <stdio.h>
#include <stdlib.h>

char string[] = "-0xff";

        long foo;
        int nchars;

        sscanf(string, "%li%n", &foo, &nchars);

        if (foo != -255 || string[nchars] != '\0')

        return 0;

	Not provided.