Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #58544

Re: More trouble with strtoul

From Melzzzzz <mel@zzzzz.com>
Newsgroups comp.lang.c
Subject Re: More trouble with strtoul
Date 2015-03-20 21:55 +0100
Organization albasani.net
Message-ID <20150320215548.05dd422e@maxa-pc> (permalink)
References <meghap$4dk$1@speranza.aioe.org> <6ilnga1dp3mj4vaj8oee3jqvmf73qus1jt@4ax.com> <mego9f$mj3$1@speranza.aioe.org>

Show all headers | View raw


On Fri, 20 Mar 2015 10:12:15 +0100
jacob navia <jacob@jacob.remcomp.fr> wrote:

> Le 20/03/2015 09:36, Robert Wessel a écrit :
> > does the GCC version set ERRNO correctly?
> 
> YES! THAT's the thing to test.
> 
> I copiled following program with gcc:
> 
>    1 #include <stdio.h>
>    2 #include <math.h>
>    3 #include <stdlib.h>
>    4 #include <errno.h>
>    5 int main(int argc,char *argv[])
>    6 {
>    7     char *end;
>    8     char *s = "-2147483647";
>    9     if (argc > 1)
>   10         s = argv[1];
>   11     errno = 0;
>   12     unsigned long m = strtoul(s,&end,0);
>   13     printf("%lu %lld",m,end-s);
>   14     printf(" errno = %s\n",strerror(errno));

gcc 4.9.2 segfaults if string.h is not included.

>   15 }
> 
> and obtained
> 
>    1 1 11 errno = Result too large
> 
> Then, since I set errno to zero at line 11, that gcc is setting errno 
> correctly meaning that this is an error, but not returning the error 
> result, meaning it is negating something after the overflow.
> 
> Is this a bug in gcc?
> 
> Looks like but I can't really say this... If MSVC and gcc agree on
> this it doesn't look very favorably to me.
> 
> What do you think?

[bmaxa@maxa-pc examples]$ gcc -m32 -g jstrtoul.c -o jstrtoul
[bmaxa@maxa-pc examples]$ ./jstrtoul 
2147483649 11 errno = Success
[bmaxa@maxa-pc examples]$ gcc -m64 -g jstrtoul.c -o jstrtoul
[bmaxa@maxa-pc examples]$ ./jstrtoul 
18446744071562067969 11 errno = Success
[bmaxa@maxa-pc examples]$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.2/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: /build/gcc-multilib/src/gcc-4.9-20150304/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 --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch --disable-libssp --enable-gnu-unique-object --enable-linker-build-id --enable-cloog-backend=isl --enable-lto --enable-plugin --enable-install-libiberty --with-linker-hash-style=gnu --enable-multilib --disable-werror --enable-checking=release
Thread model: posix
gcc version 4.9.2 20150304 (prerelease) (GCC) 

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

More trouble with strtoul jacob navia <jacob@jacob.remcomp.fr> - 2015-03-20 08:13 +0100
  Re: More trouble with strtoul Richard Heathfield <rjh@cpax.org.uk> - 2015-03-20 07:31 +0000
  Re: More trouble with strtoul Robert Wessel <robertwessel2@yahoo.com> - 2015-03-20 03:36 -0500
    Re: More trouble with strtoul Richard Heathfield <rjh@cpax.org.uk> - 2015-03-20 08:42 +0000
    Re: More trouble with strtoul jacob navia <jacob@jacob.remcomp.fr> - 2015-03-20 10:12 +0100
      Re: More trouble with strtoul Richard Heathfield <rjh@cpax.org.uk> - 2015-03-20 10:16 +0000
        Re: More trouble with strtoul: BUG in MSVC jacob navia <jacob@jacob.remcomp.fr> - 2015-03-20 11:49 +0100
      Re: More trouble with strtoul Robert Wessel <robertwessel2@yahoo.com> - 2015-03-20 05:54 -0500
      Re: More trouble with strtoul Barry Schwarz <schwarzb@dqel.com> - 2015-03-20 08:16 -0700
        Re: More trouble with strtoul jacob navia <jacob@jacob.remcomp.fr> - 2015-03-20 16:31 +0100
      Re: More trouble with strtoul Keith Thompson <kst-u@mib.org> - 2015-03-20 08:48 -0700
        Re: More trouble with strtoul jacob navia <jacob@jacob.remcomp.fr> - 2015-03-20 16:51 +0100
          Re: More trouble with strtoul Keith Thompson <kst-u@mib.org> - 2015-03-20 09:21 -0700
            Re: More trouble with strtoul jacob navia <jacob@jacob.remcomp.fr> - 2015-03-20 17:53 +0100
        Re: More trouble with strtoul glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-03-20 17:23 +0000
          Re: More trouble with strtoul jacob navia <jacob@jacob.remcomp.fr> - 2015-03-20 18:25 +0100
          Re: More trouble with strtoul Keith Thompson <kst-u@mib.org> - 2015-03-20 10:35 -0700
            Re: More trouble with strtoul Ian Collins <ian-news@hotmail.com> - 2015-03-21 08:52 +1300
              Re: More trouble with strtoul Keith Thompson <kst-u@mib.org> - 2015-03-20 13:41 -0700
      Re: More trouble with strtoul Ian Collins <ian-news@hotmail.com> - 2015-03-21 08:45 +1300
        Re: More trouble with strtoul Ian Collins <ian-news@hotmail.com> - 2015-03-21 08:47 +1300
        Re: More trouble with strtoul jacob navia <jacob@jacob.remcomp.fr> - 2015-03-20 21:16 +0100
          Re: More trouble with strtoul Ian Collins <ian-news@hotmail.com> - 2015-03-21 09:33 +1300
      Re: More trouble with strtoul Kaz Kylheku <kaz@kylheku.com> - 2015-03-20 20:05 +0000
      Re: More trouble with strtoul Melzzzzz <mel@zzzzz.com> - 2015-03-20 21:55 +0100
        Re: More trouble with strtoul Ian Collins <ian-news@hotmail.com> - 2015-03-21 11:13 +1300
          Re: More trouble with strtoul Melzzzzz <mel@zzzzz.com> - 2015-03-20 23:41 +0100
            Re: More trouble with strtoul Keith Thompson <kst-u@mib.org> - 2015-03-20 16:27 -0700
              Re: More trouble with strtoul Melzzzzz <mel@zzzzz.com> - 2015-03-21 01:47 +0100
          Re: More trouble with strtoul Richard Heathfield <rjh@cpax.org.uk> - 2015-03-21 02:03 +0000
            Re: More trouble with strtoul Ian Collins <ian-news@hotmail.com> - 2015-03-21 15:13 +1300
              Re: More trouble with strtoul Melzzzzz <mel@zzzzz.com> - 2015-03-21 03:22 +0100
              Re: More trouble with strtoul Richard Heathfield <rjh@cpax.org.uk> - 2015-03-21 02:25 +0000
  Re: More trouble with strtoul Lőrinczy Zsigmond <zsiga@nospam.for.me> - 2015-03-20 10:11 +0100
    Re: More trouble with strtoul Robert Wessel <robertwessel2@yahoo.com> - 2015-03-20 06:13 -0500
  Re: More trouble with strtoul Keith Thompson <kst-u@mib.org> - 2015-03-20 09:05 -0700
    Re: More trouble with strtoul jacob navia <jacob@jacob.remcomp.fr> - 2015-03-20 17:35 +0100
      Re: More trouble with strtoul Keith Thompson <kst-u@mib.org> - 2015-03-20 10:56 -0700
        Re: More trouble with strtoul Robert Wessel <robertwessel2@yahoo.com> - 2015-03-20 15:31 -0500
  Re: More trouble with strtoul jacob navia <jacob@jacob.remcomp.fr> - 2015-03-20 18:28 +0100
    Re: More trouble with strtoul Ian Collins <ian-news@hotmail.com> - 2015-03-21 09:01 +1300
      Re: More trouble with strtoul jacob navia <jacob@jacob.remcomp.fr> - 2015-03-20 21:12 +0100
        Re: More trouble with strtoul Kaz Kylheku <kaz@kylheku.com> - 2015-03-20 20:21 +0000
        Re: More trouble with strtoul Ian Collins <ian-news@hotmail.com> - 2015-03-21 09:36 +1300
        Re: More trouble with strtoul Robert Wessel <robertwessel2@yahoo.com> - 2015-03-20 15:47 -0500
          Re: More trouble with strtoul Kaz Kylheku <kaz@kylheku.com> - 2015-03-20 21:20 +0000
            Re: More trouble with strtoul Robert Wessel <robertwessel2@yahoo.com> - 2015-03-21 00:24 -0500
          Re: More trouble with strtoul jacob navia <jacob@jacob.remcomp.fr> - 2015-03-20 23:04 +0100
      Re: More trouble with strtoul Keith Thompson <kst-u@mib.org> - 2015-03-20 13:41 -0700
  Re: More trouble with strtoul raltbos@xs4all.nl (Richard Bos) - 2015-03-21 22:49 +0000
    Re: More trouble with strtoul Keith Thompson <kst-u@mib.org> - 2015-03-21 16:17 -0700
      Re: More trouble with strtoul Tim Rentsch <txr@alumni.caltech.edu> - 2015-03-24 12:01 -0700

csiph-web