From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 34389 invoked by alias); 1 Oct 2015 15:07:04 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 34342 invoked by uid 48); 1 Oct 2015 15:07:00 -0000 From: "8826055 at 163 dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/67799] New: The function strtoul and strtoull in do not work correctly Date: Thu, 01 Oct 2015 15:07:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 5.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: 8826055 at 163 dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2015-10/txt/msg00060.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67799 Bug ID: 67799 Summary: The function strtoul and strtoull in do not work correctly Product: gcc Version: 5.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: 8826055 at 163 dot com Target Milestone: --- Created attachment 36433 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=36433&action=edit Preprocessed File In general, they convert a char sequence representing a negative value to its complement, while it should be the maximum positive value which can be represented by unsigned long (or unsigned long long) by www.cplusplus.com Here is the code: #include #include #include using namespace std; int main() { cout << strtoul("-2", nullptr, 10) << endl; cout << ULONG_MAX << endl; cout << strtoull("-2", nullptr, 10) << endl; cout << ULLONG_MAX << endl; return 0; } and the output is: 4294967294 4294967295 18446744073709551614 18446744073709551615 I use the IDE CodeBlocks to help compile the source file. The following is the build log. Using built-in specs. COLLECT_GCC=g++.exe Target: x86_64-w64-mingw32 Configured with: ../../../src/gcc-5.2.0/configure --host=x86_64-w64-mingw32 --build=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 --prefix=/mingw64 --with-sysroot=/c/mingw520/x86_64-520-posix-seh-rt_v4-rev0/mingw64 --with-gxx-include-dir=/mingw64/x86_64-w64-mingw32/include/c++ --enable-shared --enable-static --disable-multilib --enable-languages=c,c++,fortran,objc,obj-c++,lto --enable-libstdcxx-time=yes --enable-threads=posix --enable-libgomp --enable-libatomic --enable-lto --enable-graphite --enable-checking=release --enable-fully-dynamic-string --enable-version-specific-runtime-libs --disable-isl-version-check --disable-libstdcxx-pch --disable-libstdcxx-debug --enable-bootstrap --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-gnu-as --with-gnu-ld --with-arch=nocona --with-tune=core2 --with-libiconv --with-system-zlib --with-gmp=/c/mingw520/prerequisites/x86_64-w64-mingw32-static --with-mpfr=/c/mingw520/prerequisites/x86_64-w64-mingw32-static --with-mpc=/c/mingw520/prerequisites/x86_64-w64-mingw32-static --with-isl=/c/mingw520/prerequisites/x86_64-w64-mingw32-static --with-pkgversion='x86_64-posix-seh-rev0, Built by MinGW-W64 project' --with-bugurl=http://sourceforge.net/projects/mingw-w64 CFLAGS='-O2 -pipe -I/c/mingw520/x86_64-520-posix-seh-rt_v4-rev0/mingw64/opt/include -I/c/mingw520/prerequisites/x86_64-zlib-static/include -I/c/mingw520/prerequisites/x86_64-w64-mingw32-static/include' CXXFLAGS='-O2 -pipe -I/c/mingw520/x86_64-520-posix-seh-rt_v4-rev0/mingw64/opt/include -I/c/mingw520/prerequisites/x86_64-zlib-static/include -I/c/mingw520/prerequisites/x86_64-w64-mingw32-static/include' CPPFLAGS= LDFLAGS='-pipe -L/c/mingw520/x86_64-520-posix-seh-rt_v4-rev0/mingw64/opt/lib -L/c/mingw520/prerequisites/x86_64-zlib-static/lib -L/c/mingw520/prerequisites/x86_64-w64-mingw32-static/lib ' Thread model: posix gcc version 5.2.0 (x86_64-posix-seh-rev0, Built by MinGW-W64 project) COLLECT_GCC_OPTIONS='-Wall' '-fexceptions' '-v' '-save-temps' '-O2' '-std=c++14' '-c' '-o' 'obj\Release\main.o' '-shared-libgcc' '-mtune=core2' '-march=nocona' D:/mingw-w64/x86_64-5.2.0-posix-seh-rt_v4-rev0/mingw64/bin/../libexec/gcc/x86_64-w64-mingw32/5.2.0/cc1plus.exe -E -quiet -v -iprefix D:/mingw-w64/x86_64-5.2.0-posix-seh-rt_v4-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.2.0/ -D_REENTRANT D:\C++Program\test\main.cpp -mtune=core2 -march=nocona -std=c++14 -Wall -fexceptions -O2 -fpch-preprocess -o main.ii ignoring duplicate directory "D:/mingw-w64/x86_64-5.2.0-posix-seh-rt_v4-rev0/mingw64/lib/gcc/../../lib/gcc/x86_64-w64-mingw32/5.2.0/include" ignoring nonexistent directory "C:/mingw520/x86_64-520-posix-seh-rt_v4-rev0/mingw64C:/msys64/mingw64/lib/gcc/x86_64-w64-mingw32/5.2.0/../../../../include" ignoring duplicate directory "D:/mingw-w64/x86_64-5.2.0-posix-seh-rt_v4-rev0/mingw64/lib/gcc/../../lib/gcc/x86_64-w64-mingw32/5.2.0/include-fixed" ignoring duplicate directory "D:/mingw-w64/x86_64-5.2.0-posix-seh-rt_v4-rev0/mingw64/lib/gcc/../../lib/gcc/x86_64-w64-mingw32/5.2.0/../../../../x86_64-w64-mingw32/include" ignoring nonexistent directory "C:/mingw520/x86_64-520-posix-seh-rt_v4-rev0/mingw64/mingw/include" #include "..." search starts here: #include <...> search starts here: D:/mingw-w64/x86_64-5.2.0-posix-seh-rt_v4-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.2.0/include D:/mingw-w64/x86_64-5.2.0-posix-seh-rt_v4-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.2.0/include-fixed D:/mingw-w64/x86_64-5.2.0-posix-seh-rt_v4-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.2.0/../../../../x86_64-w64-mingw32/include D:/mingw-w64/x86_64-5.2.0-posix-seh-rt_v4-rev0/mingw64/lib/gcc/../../x86_64-w64-mingw32/include/c++ D:/mingw-w64/x86_64-5.2.0-posix-seh-rt_v4-rev0/mingw64/lib/gcc/../../x86_64-w64-mingw32/include/c++/x86_64-w64-mingw32 D:/mingw-w64/x86_64-5.2.0-posix-seh-rt_v4-rev0/mingw64/lib/gcc/../../x86_64-w64-mingw32/include/c++/backward End of search list. COLLECT_GCC_OPTIONS='-Wall' '-fexceptions' '-v' '-save-temps' '-O2' '-std=c++14' '-c' '-o' 'obj\Release\main.o' '-shared-libgcc' '-mtune=core2' '-march=nocona' D:/mingw-w64/x86_64-5.2.0-posix-seh-rt_v4-rev0/mingw64/bin/../libexec/gcc/x86_64-w64-mingw32/5.2.0/cc1plus.exe -fpreprocessed main.ii -quiet -dumpbase main.cpp -mtune=core2 -march=nocona -auxbase-strip obj\Release\main.o -O2 -Wall -std=c++14 -version -fexceptions -o main.s GNU C++14 (x86_64-posix-seh-rev0, Built by MinGW-W64 project) version 5.2.0 (x86_64-w64-mingw32) compiled by GNU C version 5.2.0, GMP version 6.0.0, MPFR version 3.1.3, MPC version 1.0.3 GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 GNU C++14 (x86_64-posix-seh-rev0, Built by MinGW-W64 project) version 5.2.0 (x86_64-w64-mingw32) compiled by GNU C version 5.2.0, GMP version 6.0.0, MPFR version 3.1.3, MPC version 1.0.3 GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 Compiler executable checksum: 21af4d84309555a285c9e50ab0605aa1 COLLECT_GCC_OPTIONS='-Wall' '-fexceptions' '-v' '-save-temps' '-O2' '-std=c++14' '-c' '-o' 'obj\Release\main.o' '-shared-libgcc' '-mtune=core2' '-march=nocona' D:/mingw-w64/x86_64-5.2.0-posix-seh-rt_v4-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.2.0/../../../../x86_64-w64-mingw32/bin/as.exe -v -o obj\Release\main.o main.s GNU assembler version 2.25 (x86_64-w64-mingw32) using BFD version (GNU Binutils) 2.25 COMPILER_PATH=D:/mingw-w64/x86_64-5.2.0-posix-seh-rt_v4-rev0/mingw64/bin/../libexec/gcc/x86_64-w64-mingw32/5.2.0/;D:/mingw-w64/x86_64-5.2.0-posix-seh-rt_v4-rev0/mingw64/bin/../libexec/gcc/;D:/mingw-w64/x86_64-5.2.0-posix-seh-rt_v4-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.2.0/../../../../x86_64-w64-mingw32/bin/ LIBRARY_PATH=D:/mingw-w64/x86_64-5.2.0-posix-seh-rt_v4-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.2.0/;D:/mingw-w64/x86_64-5.2.0-posix-seh-rt_v4-rev0/mingw64/bin/../lib/gcc/;D:/mingw-w64/x86_64-5.2.0-posix-seh-rt_v4-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.2.0/../../../../x86_64-w64-mingw32/lib/../lib/;D:/mingw-w64/x86_64-5.2.0-posix-seh-rt_v4-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.2.0/../../../../lib/;D:/mingw-w64/x86_64-5.2.0-posix-seh-rt_v4-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.2.0/../../../../x86_64-w64-mingw32/lib/;D:/mingw-w64/x86_64-5.2.0-posix-seh-rt_v4-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/5.2.0/../../../ COLLECT_GCC_OPTIONS='-Wall' '-fexceptions' '-v' '-save-temps' '-O2' '-std=c++14' '-c' '-o' 'obj\Release\main.o' '-shared-libgcc' '-mtune=core2' '-march=nocona' g++.exe -o bin\Release\test.exe obj\Release\main.o -s Output file is bin\Release\test.exe with size 18.50 KB Process terminated with status 0 (0 minute(s), 0 second(s)) 0 error(s), 0 warning(s) (0 minute(s), 0 second(s))