public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/67799] New: The function strtoul and strtoull in <cstdlib> do not work correctly
@ 2015-10-01 15:07 8826055 at 163 dot com
2015-10-01 15:14 ` [Bug c++/67799] " redi at gcc dot gnu.org
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: 8826055 at 163 dot com @ 2015-10-01 15:07 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67799
Bug ID: 67799
Summary: The function strtoul and strtoull in <cstdlib> 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 <iostream>
#include <climits>
#include <cstdlib>
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))
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/67799] The function strtoul and strtoull in <cstdlib> do not work correctly
2015-10-01 15:07 [Bug c++/67799] New: The function strtoul and strtoull in <cstdlib> do not work correctly 8826055 at 163 dot com
@ 2015-10-01 15:14 ` redi at gcc dot gnu.org
2015-10-01 15:52 ` 8826055 at 163 dot com
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2015-10-01 15:14 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67799
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |INVALID
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
If you look in <cstdlib> you will see these functions are not provided by GCC's
header, they come from your C library, so this is nothing to do with GCC.
In any case, cplusplus.com is wrong, the functions behave as required by the C
standard:
If the subject sequence begins with a minus sign, the value resulting from
the conversion is negated (in the return type).
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/67799] The function strtoul and strtoull in <cstdlib> do not work correctly
2015-10-01 15:07 [Bug c++/67799] New: The function strtoul and strtoull in <cstdlib> do not work correctly 8826055 at 163 dot com
2015-10-01 15:14 ` [Bug c++/67799] " redi at gcc dot gnu.org
@ 2015-10-01 15:52 ` 8826055 at 163 dot com
2015-10-01 16:06 ` redi at gcc dot gnu.org
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: 8826055 at 163 dot com @ 2015-10-01 15:52 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67799
8826055 at 163 dot com changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |UNCONFIRMED
Resolution|INVALID |---
--- Comment #2 from 8826055 at 163 dot com ---
(In reply to Jonathan Wakely from comment #1)
> If you look in <cstdlib> you will see these functions are not provided by
> GCC's header, they come from your C library, so this is nothing to do with
> GCC.
>
> In any case, cplusplus.com is wrong, the functions behave as required by the
> C standard:
>
> If the subject sequence begins with a minus sign, the value resulting from
> the conversion is negated (in the return type).
But the C standard also says "If the correct value is outside the range of
representable values, LONG_MIN, LONG_MAX, LLONG_MIN, LLONG_MAX, ULONG_MAX, or
ULLONG_MAX is returned (according to the return type and sign of the value, if
any)".
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/67799] The function strtoul and strtoull in <cstdlib> do not work correctly
2015-10-01 15:07 [Bug c++/67799] New: The function strtoul and strtoull in <cstdlib> do not work correctly 8826055 at 163 dot com
2015-10-01 15:14 ` [Bug c++/67799] " redi at gcc dot gnu.org
2015-10-01 15:52 ` 8826055 at 163 dot com
@ 2015-10-01 16:06 ` redi at gcc dot gnu.org
2015-10-01 16:11 ` 8826055 at 163 dot com
2015-10-01 17:22 ` msebor at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2015-10-01 16:06 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67799
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |INVALID
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Jonathan Wakely from comment #1)
> If you look in <cstdlib> you will see these functions are not provided by
> GCC's header, they come from your C library, so this is nothing to do with
> GCC.
Again, those functions have nothing to do with GCC.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/67799] The function strtoul and strtoull in <cstdlib> do not work correctly
2015-10-01 15:07 [Bug c++/67799] New: The function strtoul and strtoull in <cstdlib> do not work correctly 8826055 at 163 dot com
` (2 preceding siblings ...)
2015-10-01 16:06 ` redi at gcc dot gnu.org
@ 2015-10-01 16:11 ` 8826055 at 163 dot com
2015-10-01 17:22 ` msebor at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: 8826055 at 163 dot com @ 2015-10-01 16:11 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67799
--- Comment #4 from 8826055 at 163 dot com ---
(In reply to Jonathan Wakely from comment #3)
> (In reply to Jonathan Wakely from comment #1)
> > If you look in <cstdlib> you will see these functions are not provided by
> > GCC's header, they come from your C library, so this is nothing to do with
> > GCC.
>
> Again, those functions have nothing to do with GCC.
Thanks, I see it. I just want to confirm that such implementation conflicts
with the C standard.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/67799] The function strtoul and strtoull in <cstdlib> do not work correctly
2015-10-01 15:07 [Bug c++/67799] New: The function strtoul and strtoull in <cstdlib> do not work correctly 8826055 at 163 dot com
` (3 preceding siblings ...)
2015-10-01 16:11 ` 8826055 at 163 dot com
@ 2015-10-01 17:22 ` msebor at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: msebor at gcc dot gnu.org @ 2015-10-01 17:22 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67799
Martin Sebor <msebor at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |msebor at gcc dot gnu.org
--- Comment #5 from Martin Sebor <msebor at gcc dot gnu.org> ---
(In reply to 8826055 from comment #4)
For POSIX, see http://austingroupbugs.net/view.php?id=700
For GLIBC see
http://www.gnu.org/software/libc/manual/html_node/Parsing-of-Integers.html
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2015-10-01 17:22 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-01 15:07 [Bug c++/67799] New: The function strtoul and strtoull in <cstdlib> do not work correctly 8826055 at 163 dot com
2015-10-01 15:14 ` [Bug c++/67799] " redi at gcc dot gnu.org
2015-10-01 15:52 ` 8826055 at 163 dot com
2015-10-01 16:06 ` redi at gcc dot gnu.org
2015-10-01 16:11 ` 8826055 at 163 dot com
2015-10-01 17:22 ` msebor at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).