This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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

Attachment: 0001-newlib-libc-stdio-nano-vfscanf.c-Fix-X-specifier-pro.patch
Description: Binary data


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]