[Bug libgcc/67154] New: sscanf does not extract correct value when the format is "%c" and the location is of type int*
wondertx at gmail dot com
gcc-bugzilla@gcc.gnu.org
Sat Aug 8 02:37:00 GMT 2015
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67154
Bug ID: 67154
Summary: sscanf does not extract correct value when the format
is "%c" and the location is of type int*
Product: gcc
Version: 5.2.0
Status: UNCONFIRMED
Severity: critical
Priority: P3
Component: libgcc
Assignee: unassigned at gcc dot gnu.org
Reporter: wondertx at gmail dot com
Target Milestone: ---
#include <iostream>
#include <string>
#include <cstdio>
using std::cout;
using std::endl;
int main()
{
std::string s { 'a', 'b', 'c' };
cout << s << endl;
int a;
int b, c;
int ret;
ret = sscanf(s.c_str(), "%c%c%c", &a, &b, &c);
cout << a << ' ' << b << ' ' << c << endl;
cout << "ret " << ret << endl;
return 0;
}
The output is:
abc
97 4197986 99
ret 3
Output of gcc -v :
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-unknown-linux-gnu/5.2.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: /build/gcc/src/gcc-5.2.0/configure --prefix=/usr
--libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man
--infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/
--enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++ --enable-shared
--enable-threads=posix --enable-libmpx --with-system-zlib --with-isl
--enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu
--disable-libstdcxx-pch --disable-libssp --enable-gnu-unique-object
--enable-linker-build-id --enable-lto --enable-plugin
--enable-install-libiberty --with-linker-hash-style=gnu
--enable-gnu-indirect-function --disable-multilib --disable-werror
--enable-checking=release --with-default-libstdcxx-abi=gcc4-compatible
Thread model: posix
gcc version 5.2.0 (GCC)
More information about the Gcc-bugs
mailing list