I am using GCC 4.8 and glibc 2.19 on an x86_64 Linux.
While playing with different input methods for a different question, I compared fscanf
and s
It looks like glibc's sscanf()
scans the source string for the length before doing anything else.
sscanf()
(in stdio-common/sscanf.c
) is essentially a wrapper around a call to _IO_vsscanf()
(in libio/iovsscanf.c
). And one of the first things that _IO_vsscanf()
does is initialize its own _IO_strfile
structure by calling _IO_str_init_static_internal()
(in libio/strops.c
) which calculates the length of the string if it's not provided.