From nobody@FreeBSD.org  Fri Aug  9 00:15:41 2013
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1])
	(using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by hub.freebsd.org (Postfix) with ESMTP id 6EBC54F6
	for <freebsd-gnats-submit@FreeBSD.org>; Fri,  9 Aug 2013 00:15:41 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from oldred.freebsd.org (oldred.freebsd.org [8.8.178.121])
	(using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by mx1.freebsd.org (Postfix) with ESMTPS id 5ACF82D77
	for <freebsd-gnats-submit@FreeBSD.org>; Fri,  9 Aug 2013 00:15:41 +0000 (UTC)
Received: from oldred.freebsd.org ([127.0.1.6])
	by oldred.freebsd.org (8.14.5/8.14.7) with ESMTP id r790FfW2041026
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 9 Aug 2013 00:15:41 GMT
	(envelope-from nobody@oldred.freebsd.org)
Received: (from nobody@localhost)
	by oldred.freebsd.org (8.14.5/8.14.5/Submit) id r790Ffau041019;
	Fri, 9 Aug 2013 00:15:41 GMT
	(envelope-from nobody)
Message-Id: <201308090015.r790Ffau041019@oldred.freebsd.org>
Date: Fri, 9 Aug 2013 00:15:41 GMT
From: Garrett Cooper <yaneurabeya@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: %i fails with negative hex numbers with sscanf
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         181152
>Category:       kern
>Synopsis:       [libc] %i fails with negative hex numbers with sscanf(3)
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Aug 09 00:20:00 UTC 2013
>Closed-Date:    
>Last-Modified:  Fri Aug  9 02:10:00 UTC 2013
>Originator:     Garrett Cooper
>Release:        10-CURRENT
>Organization:
EMC Isilon
>Environment:
FreeBSD fuji-current.local 10.0-CURRENT FreeBSD 10.0-CURRENT #10 c9d2bd6-dirty: Wed Aug  7 18:55:03 PDT 2013     root@fuji-current.local:/usr/obj/usr/src/sys/FUJI-NOCOMPAT  i386
>Description:
Looks like FreeBSD has lib/21691:

    sscanf_neghex: [0.001912s] Failed: /usr/src/lib/libc/tests/stdio/t_scanf.c:50: i == NUM not met

The snippet of test code that exhibits this is:

#define NUM     -0x1234
#define STRNUM  __STRING(NUM)

ATF_TC(sscanf_neghex);
ATF_TC_HEAD(sscanf_neghex, tc)
{
        atf_tc_set_md_var(tc, "descr",
            "PR lib/21691: %%i and %%x fail with negative hex numbers");
}

ATF_TC_BODY(sscanf_neghex, tc)
{
        int i;

        sscanf(STRNUM, "%i", &i);
        ATF_REQUIRE(i == NUM);

        sscanf(STRNUM, "%x", &i);
        ATF_REQUIRE(i == NUM);
}
>How-To-Repeat:

>Fix:


>Release-Note:
>Audit-Trail:

From: Andrey Chernov <ache@freebsd.org>
To: Garrett Cooper <yaneurabeya@gmail.com>
Cc: freebsd-gnats-submit@FreeBSD.org
Subject: Re: bin/181152: %i fails with negative hex numbers with sscanf
Date: Fri, 09 Aug 2013 06:05:04 +0400

 On 09.08.2013 4:15, Garrett Cooper wrote:
 > #define NUM     -0x1234
 > #define STRNUM  __STRING(NUM)
 > 
 > ATF_TC(sscanf_neghex);
 > ATF_TC_HEAD(sscanf_neghex, tc)
 > {
 >         atf_tc_set_md_var(tc, "descr",
 >             "PR lib/21691: %%i and %%x fail with negative hex numbers");
 > }
 > 
 > ATF_TC_BODY(sscanf_neghex, tc)
 > {
 >         int i;
 > 
 >         sscanf(STRNUM, "%i", &i);
 >         ATF_REQUIRE(i == NUM);
 > 
 >         sscanf(STRNUM, "%x", &i);
 >         ATF_REQUIRE(i == NUM);
 > }
 
 Probably something is wrong with your ATF way, this example works:
 
 #include <stdio.h>
 
 int main() {
 int i;
 i = 0;
 sscanf("-0x1234", "%i", &i);
 printf("%d\n", i);
 i = 0;
 sscanf("-0x1234", "%x", &i);
 printf("%d\n", i);
 }
 
 -4660
 -4660
 (which is -0x1234)
 
 Please do not post more ATF examples, use plain ones, many developers
 (including me) don't have ATF installed.
 
 -- 
 http://ache.vniz.net/
 bitcoin:1G6ugdNY6e5jx1GVnAU2ntj2NEfmjKG85r
>Unformatted:
