Bug 181152 - [libc] %i fails with negative hex numbers with sscanf(3)
Summary: [libc] %i fails with negative hex numbers with sscanf(3)
Status: Open
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: Unspecified
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-08-09 01:20 UTC by Enji Cooper
Modified: 2018-01-03 05:16 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Enji Cooper freebsd_committer freebsd_triage 2013-08-09 01:20:00 UTC
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);
}
Comment 1 Andrey A. Chernov freebsd_committer freebsd_triage 2013-08-09 03:05:04 UTC
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
Comment 2 Eitan Adler freebsd_committer freebsd_triage 2017-12-31 07:59:42 UTC
For bugs matching the following criteria:

Status: In Progress Changed: (is less than) 2014-06-01

Reset to default assignee and clear in-progress tags.

Mail being skipped