[newlib][PATCH] nano version of sscanf does not work with %X (capital letter) specifier

Igor Venevtsev igor.venevtsev@gmail.com
Mon Feb 1 14:53:00 GMT 2016


This code prints GOT :F: instead of GOT :15: in case of newlib was
configured with --enable-newlib-nano-formatted-io:

bash-4.3$ cat test.c && gcc -m32 test.c -I i386-elf/include/ -nostdlib
i386-elf/lib/libc.a i386-elf/lib/libnosys.a && ./a.out
#include <stdio.h>

int main()
{
    char *in = "15\n";
    unsigned int a;
    sscanf(in, "%X\n", &a);
    fprintf(stderr, "GOT :%X:\n", a);
    return 0;
}

void __attribute__((noreturn)) exit(int code) {
    for (;;)
        asm volatile ("int $0x80" : : "a"(1), "b"(code));
}

int write(int fd, char* buf, int size)
{
    asm volatile ("int $0x80" : : "a"(4), "b"(fd), "c"(buf), "d"(size));
}

void _start()
{
    exit(main());
}

GOT :F:

The reason is trivial - missing case 'X': clause.

Please find the patch in attchment.

Thanks, Igor
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-newlib-libc-stdio-nano-vfscanf.c-Fix-X-specifier-pro.patch
Type: application/octet-stream
Size: 723 bytes
Desc: not available
URL: <http://sourceware.org/pipermail/newlib/attachments/20160201/982369b0/attachment.obj>


More information about the Newlib mailing list