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


Groups > comp.lang.c > #58467 > unrolled thread

More trouble with strtoul

Started byjacob navia <jacob@jacob.remcomp.fr>
First post2015-03-20 08:13 +0100
Last post2015-03-24 12:01 -0700
Articles 20 on this page of 52 — 12 participants

Back to article view | Back to comp.lang.c


Contents

  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

Page 2 of 3 — ← Prev page 1 [2] 3  Next page →


#58531

FromIan Collins <ian-news@hotmail.com>
Date2015-03-21 08:47 +1300
Message-ID<cn3bq0F9khqU5@mid.individual.net>
In reply to#58530
Ian Collins wrote:
> On Linux and Solaris, compiling (with the missing header added) with:
>
> gcc -std=c99 -pedantic -Wall x.c -m64; ./a.out
> -2147483647 11 errno = Success
>
> gcc -std=c99 -pedantic -Wall x.c -m32; ./a.out
> -2147483647 11 errno = Success

I forgot to mention I used

   printf("%ld %td",m,end-s);

-- 
Ian Collins

[toc] | [prev] | [next] | [standalone]


#58536

Fromjacob navia <jacob@jacob.remcomp.fr>
Date2015-03-20 21:16 +0100
Message-ID<mehv65$4fl$3@speranza.aioe.org>
In reply to#58530
Le 20/03/2015 20:45, Ian Collins a écrit :

> Platform library issue more like.
>
> On Linux and Solaris, compiling (with the missing header added) with:
>
> gcc -std=c99 -pedantic -Wall x.c -m64; ./a.out
> -2147483647 11 errno = Success
>
> gcc -std=c99 -pedantic -Wall x.c -m32; ./a.out
> -2147483647 11 errno = Success
>
sizeof(long) in your system is what?

sizeof(long) is 4 in my system (64 bit windows)

[toc] | [prev] | [next] | [standalone]


#58539

FromIan Collins <ian-news@hotmail.com>
Date2015-03-21 09:33 +1300
Message-ID<cn3egmF9khqU8@mid.individual.net>
In reply to#58536
jacob navia wrote:
> Le 20/03/2015 20:45, Ian Collins a écrit :
>
>> Platform library issue more like.
>>
>> On Linux and Solaris, compiling (with the missing header added) with:
>>
>> gcc -std=c99 -pedantic -Wall x.c -m64; ./a.out
>> -2147483647 11 errno = Success
>>
>> gcc -std=c99 -pedantic -Wall x.c -m32; ./a.out
>> -2147483647 11 errno = Success
>>
> sizeof(long) in your system is what?

4 or 8 depending on compilation mode.

-- 
Ian Collins

[toc] | [prev] | [next] | [standalone]


#58534

FromKaz Kylheku <kaz@kylheku.com>
Date2015-03-20 20:05 +0000
Message-ID<20150320125258.839@kylheku.com>
In reply to#58478
On 2015-03-20, jacob navia <jacob@jacob.remcomp.fr> wrote:
> Is this a bug in gcc?

It cannot be, because gcc does not provide strtoul.

Which is not to say that it has *no* library; it has a small run-time
library:

Reference: https://gcc.gnu.org/onlinedocs/gccint/Libgcc.html

This does not contain strtoul.

[toc] | [prev] | [next] | [standalone]


#58544

FromMelzzzzz <mel@zzzzz.com>
Date2015-03-20 21:55 +0100
Message-ID<20150320215548.05dd422e@maxa-pc>
In reply to#58478
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) 

[toc] | [prev] | [next] | [standalone]


#58547

FromIan Collins <ian-news@hotmail.com>
Date2015-03-21 11:13 +1300
Message-ID<cn3kcrF9khqU10@mid.individual.net>
In reply to#58544
Melzzzzz wrote:
> 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.

Now that's a suitable bug to report to the gcc bug tracker!

-- 
Ian Collins

[toc] | [prev] | [next] | [standalone]


#58549

FromMelzzzzz <mel@zzzzz.com>
Date2015-03-20 23:41 +0100
Message-ID<20150320234115.13546608@maxa-pc>
In reply to#58547
On Sat, 21 Mar 2015 11:13:43 +1300
Ian Collins <ian-news@hotmail.com> wrote:

> Melzzzzz wrote:
> > 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.
> 
> Now that's a suitable bug to report to the gcc bug tracker!
> 

I dunno if this is bug or feature:

[bmaxa@maxa-pc examples]$ gcc -Wall -Wextra -m32 -g jstrtoul.c -o
jstrtoul jstrtoul.c: In function ‘main’:
jstrtoul.c:15:3: warning: implicit declaration of function
‘strerror’ [-Wimplicit-function-declaration] printf(" errno =
%s\n",strerror(errno)); ^
jstrtoul.c:15:3: warning: format ‘%s’ expects argument of type ‘char
*’, but argument 2 has type ‘int’ [-Wformat=] jstrtoul.c:16:1: warning:
control reaches end of non-void function [-Wreturn-type] }

[toc] | [prev] | [next] | [standalone]


#58550

FromKeith Thompson <kst-u@mib.org>
Date2015-03-20 16:27 -0700
Message-ID<87lhirw8ps.fsf@kst-u.example.com>
In reply to#58549
Melzzzzz <mel@zzzzz.com> writes:
> On Sat, 21 Mar 2015 11:13:43 +1300
> Ian Collins <ian-news@hotmail.com> wrote:
>> Melzzzzz wrote:
>> > 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.
>> 
>> Now that's a suitable bug to report to the gcc bug tracker!
>> 
>
> I dunno if this is bug or feature:
>
> [bmaxa@maxa-pc examples]$ gcc -Wall -Wextra -m32 -g jstrtoul.c -o
> jstrtoul jstrtoul.c: In function ‘main’:
> jstrtoul.c:15:3: warning: implicit declaration of function
> ‘strerror’ [-Wimplicit-function-declaration] printf(" errno =
> %s\n",strerror(errno)); ^
> jstrtoul.c:15:3: warning: format ‘%s’ expects argument of type ‘char
> *’, but argument 2 has type ‘int’ [-Wformat=] jstrtoul.c:16:1: warning:
> control reaches end of non-void function [-Wreturn-type] }

I presume you meant that the code generated by gcc segfaults, not that
the compiler itself crashes.

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

[toc] | [prev] | [next] | [standalone]


#58552

FromMelzzzzz <mel@zzzzz.com>
Date2015-03-21 01:47 +0100
Message-ID<20150321014736.7f37be67@maxa-pc>
In reply to#58550
On Fri, 20 Mar 2015 16:27:27 -0700
Keith Thompson <kst-u@mib.org> wrote:

> Melzzzzz <mel@zzzzz.com> writes:
> > On Sat, 21 Mar 2015 11:13:43 +1300
> > Ian Collins <ian-news@hotmail.com> wrote:
> >> Melzzzzz wrote:
> >> > 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.
> >> 
> >> Now that's a suitable bug to report to the gcc bug tracker!
> >> 
> >
> > I dunno if this is bug or feature:
> >
> > [bmaxa@maxa-pc examples]$ gcc -Wall -Wextra -m32 -g jstrtoul.c -o
> > jstrtoul jstrtoul.c: In function ‘main’:
> > jstrtoul.c:15:3: warning: implicit declaration of function
> > ‘strerror’ [-Wimplicit-function-declaration] printf(" errno =
> > %s\n",strerror(errno)); ^
> > jstrtoul.c:15:3: warning: format ‘%s’ expects argument of type ‘char
> > *’, but argument 2 has type ‘int’ [-Wformat=] jstrtoul.c:16:1:
> > warning: control reaches end of non-void function [-Wreturn-type] }
> 
> I presume you meant that the code generated by gcc segfaults, not that
> the compiler itself crashes.
> 

Yes, generated code segfaults.

[toc] | [prev] | [next] | [standalone]


#58553

FromRichard Heathfield <rjh@cpax.org.uk>
Date2015-03-21 02:03 +0000
Message-ID<meijfe$bqn$1@dont-email.me>
In reply to#58547
On 20/03/15 22:13, Ian Collins wrote:
> Melzzzzz wrote:
>> On Fri, 20 Mar 2015 10:12:15 +0100
>> jacob navia <jacob@jacob.remcomp.fr> wrote:

<snip>

>>>    14     printf(" errno = %s\n",strerror(errno));
>>
>> gcc 4.9.2 segfaults if string.h is not included.
>
> Now that's a suitable bug to report to the gcc bug tracker!

Why? What's the bug, precisely? I'd have said it was a user-programmer 
problem. Presumably gcc produces a diagnostic message for the absence of 
a prototype? Or is the absence of such a message the bug to which you refer?

-- 
Richard Heathfield
Email: rjh at cpax dot org dot uk
"Usenet is a strange place" - dmr 29 July 1999
Sig line 4 vacant - apply within

[toc] | [prev] | [next] | [standalone]


#58554

FromIan Collins <ian-news@hotmail.com>
Date2015-03-21 15:13 +1300
Message-ID<cn42dfF9khqU11@mid.individual.net>
In reply to#58553
Richard Heathfield wrote:
> On 20/03/15 22:13, Ian Collins wrote:
>> Melzzzzz wrote:
>>> On Fri, 20 Mar 2015 10:12:15 +0100
>>> jacob navia <jacob@jacob.remcomp.fr> wrote:
>
> <snip>
>
>>>>     14     printf(" errno = %s\n",strerror(errno));
>>>
>>> gcc 4.9.2 segfaults if string.h is not included.
>>
>> Now that's a suitable bug to report to the gcc bug tracker!
>
> Why? What's the bug, precisely? I'd have said it was a user-programmer
> problem. Presumably gcc produces a diagnostic message for the absence of
> a prototype? Or is the absence of such a message the bug to which you refer?

"gcc 4.9.2 segfaults if string.h is not included".  If one of my 
application crashed when it should issue a diagnostic, I'd consider it a 
bug.

-- 
Ian Collins

[toc] | [prev] | [next] | [standalone]


#58555

FromMelzzzzz <mel@zzzzz.com>
Date2015-03-21 03:22 +0100
Message-ID<20150321032211.7cc76f64@maxa-pc>
In reply to#58554
On Sat, 21 Mar 2015 15:13:02 +1300
Ian Collins <ian-news@hotmail.com> wrote:

> Richard Heathfield wrote:
> > On 20/03/15 22:13, Ian Collins wrote:
> >> Melzzzzz wrote:
> >>> On Fri, 20 Mar 2015 10:12:15 +0100
> >>> jacob navia <jacob@jacob.remcomp.fr> wrote:
> >
> > <snip>
> >
> >>>>     14     printf(" errno = %s\n",strerror(errno));
> >>>
> >>> gcc 4.9.2 segfaults if string.h is not included.
> >>
> >> Now that's a suitable bug to report to the gcc bug tracker!
> >
> > Why? What's the bug, precisely? I'd have said it was a
> > user-programmer problem. Presumably gcc produces a diagnostic
> > message for the absence of a prototype? Or is the absence of such a
> > message the bug to which you refer?
> 
> "gcc 4.9.2 segfaults if string.h is not included".  If one of my 
> application crashed when it should issue a diagnostic, I'd consider
> it a bug.
> 

I meant generated code crashes. Sorry. Compiler issues a warning about
missing prototype.

[toc] | [prev] | [next] | [standalone]


#58556

FromRichard Heathfield <rjh@cpax.org.uk>
Date2015-03-21 02:25 +0000
Message-ID<meikp2$t1u$1@dont-email.me>
In reply to#58554
On 21/03/15 02:13, Ian Collins wrote:
> Richard Heathfield wrote:
>> On 20/03/15 22:13, Ian Collins wrote:
>>> Melzzzzz wrote:
>>>> On Fri, 20 Mar 2015 10:12:15 +0100
>>>> jacob navia <jacob@jacob.remcomp.fr> wrote:
>>
>> <snip>
>>
>>>>>     14     printf(" errno = %s\n",strerror(errno));
>>>>
>>>> gcc 4.9.2 segfaults if string.h is not included.
>>>
>>> Now that's a suitable bug to report to the gcc bug tracker!
>>
>> Why? What's the bug, precisely? I'd have said it was a user-programmer
>> problem. Presumably gcc produces a diagnostic message for the absence of
>> a prototype? Or is the absence of such a message the bug to which you refer?
>
> "gcc 4.9.2 segfaults if string.h is not included".  If one of my
> application crashed when it should issue a diagnostic, I'd consider it a
> bug.


But that isn't what he meant. I know it's what he wrote, but that's 
neither here nor there. :-)

-- 
Richard Heathfield
Email: rjh at cpax dot org dot uk
"Usenet is a strange place" - dmr 29 July 1999
Sig line 4 vacant - apply within

[toc] | [prev] | [next] | [standalone]


#58477

FromLőrinczy Zsigmond <zsiga@nospam.for.me>
Date2015-03-20 10:11 +0100
Message-ID<mego7m$mfn$1@speranza.aioe.org>
In reply to#58467
On 2015-03-20 08:13, jacob navia wrote:
> Consider this call
>
> strtoul("-4294967296",NULL,0)
>
> This is what lcc-win returns
>
> strtoul("-4294967296",0) len=11 res=4294967295 (0xffffffff)
> strtoul("-4294967297",0) len=11 res=4294967295 (0xffffffff)
>
> This is what gcc returns
>
> strtoul("-4294967296",0) len=11 res=1 (0x1)
> strtoul("-4294967297",0) len=11 res=1 (0x1)

have you consulted glibc source (not gcc, glibc)?

it is glibc-*/elf/dl-minimal.c:__strtoul_internal

[toc] | [prev] | [next] | [standalone]


#58485

FromRobert Wessel <robertwessel2@yahoo.com>
Date2015-03-20 06:13 -0500
Message-ID<f00oga5k5b5g76d26krmjltvbdt6r5fa9f@4ax.com>
In reply to#58477
On Fri, 20 Mar 2015 10:11:27 +0100, L?rinczy Zsigmond
<zsiga@nospam.for.me> wrote:

>On 2015-03-20 08:13, jacob navia wrote:
>> Consider this call
>>
>> strtoul("-4294967296",NULL,0)
>>
>> This is what lcc-win returns
>>
>> strtoul("-4294967296",0) len=11 res=4294967295 (0xffffffff)
>> strtoul("-4294967297",0) len=11 res=4294967295 (0xffffffff)
>>
>> This is what gcc returns
>>
>> strtoul("-4294967296",0) len=11 res=1 (0x1)
>> strtoul("-4294967297",0) len=11 res=1 (0x1)
>
>have you consulted glibc source (not gcc, glibc)?
>
>it is glibc-*/elf/dl-minimal.c:__strtoul_internal


That appears to implement it correctly.

As does Apple's version:

http://www.opensource.apple.com/source/tcl/tcl-14/tcl/compat/strtoul.c

But I don't think the first one is what's in the normal glibc.

[toc] | [prev] | [next] | [standalone]


#58512

FromKeith Thompson <kst-u@mib.org>
Date2015-03-20 09:05 -0700
Message-ID<87egojy7rj.fsf@kst-u.example.com>
In reply to#58467
jacob navia <jacob@jacob.remcomp.fr> writes:
> Consider this call
>
> strtoul("-4294967296",NULL,0)
>
> This is what lcc-win returns
>
> strtoul("-4294967296",0) len=11 res=4294967295 (0xffffffff)
> strtoul("-4294967297",0) len=11 res=4294967295 (0xffffffff)
>
> This is what gcc returns
>
> strtoul("-4294967296",0) len=11 res=1 (0x1)
> strtoul("-4294967297",0) len=11 res=1 (0x1)

I can't reproduce that result on my system.  When I compile
and run this program:

    #include <stdio.h>
    #include <stdlib.h>
    #include <limits.h>
    #include <errno.h>
    int main(void) {
        printf("ULONG_MAX = %lu (0x%lx)\n", ULONG_MAX, ULONG_MAX);
        errno = 0;
        unsigned long result = strtoul("-4294967296", NULL, 0);
        printf("result = %lu (0x%lx), errno = %d",
               result, result, errno);
        if (errno == ERANGE) {
            printf(" (ERANGE)");
        }
        putchar('\n');
    }

I get:

    ULONG_MAX = 4294967295 (0xffffffff)
    result = 4294967295 (0xffffffff), errno = 34 (ERANGE)

Can you try the same program with gcc on your system?

> CONSTRAINTS:
>
> sizeof(unsigned long) == 4 (32 bits)
>
> Explanation for the lcc result:
>
> ULONG_MAX is 4294967295 (0xffffffff), so 4294967296 is clearly an overflow!
>
> In that case (an error) the software is supposed to return an error
> value (in this case ULONG_MAX).
>
> I just do not understand WHERE that "1" result from gcc is coming from.

It's not from gcc, it's from strtol(), which is implemented by the C
library.  It looks like both lcc-win and the gcc/glibc implementation on
my system handle it correctly.

What gcc implementation are you using?  What OS and runtime library?

[...]

> P.S. this can't be tested in a UNIX system since there sizeof(long)==8
> in modern Unix systems

If you have the right packages installed, you can compile with "-m32".

My system is Linux Mint 17, with gcc 4.8.2 and GNU libc6:i386 2.19.
I compiled the program with "gcc -std=c99 -m32".

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

[toc] | [prev] | [next] | [standalone]


#58515

Fromjacob navia <jacob@jacob.remcomp.fr>
Date2015-03-20 17:35 +0100
Message-ID<mehi8h$2ss$1@speranza.aioe.org>
In reply to#58512
d:\lcc\libc\test>gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=c:/tdm-gcc-64/bin/../libexec/gcc/x86_64-w64-mingw32/4.8.1/lto-wrapper.exe
Target: x86_64-w64-mingw32
Configured with: ../../../src/gcc-4.8.1/configure 
--build=x86_64-w64-mingw32 --enable-targets=all --enable-lan
guages=ada,c,c++,fortran,lto,objc,obj-c++ --enable-libgomp --enable-lto 
--enable-graphite --enable-cxx-flags=-
DWINPTHREAD_STATIC --enable-libstdcxx-debug --enable-threads=posix 
--enable-version-specific-runtime-libs --en
able-fully-dynamic-string --enable-libstdcxx-threads 
--enable-libstdcxx-time --with-gnu-ld --disable-werror --
disable-nls --disable-win32-registry --prefix=/mingw64tdm 
--with-local-prefix=/mingw64tdm --with-pkgversion=td
m64-2 --with-bugurl=http://tdm-gcc.tdragon.net/bugs
Thread model: posix
gcc version 4.8.1 (tdm64-2)

[toc] | [prev] | [next] | [standalone]


#58524

FromKeith Thompson <kst-u@mib.org>
Date2015-03-20 10:56 -0700
Message-ID<871tkjy2l2.fsf@kst-u.example.com>
In reply to#58515
jacob navia <jacob@jacob.remcomp.fr> writes:
> d:\lcc\libc\test>gcc -v
> Using built-in specs.
> COLLECT_GCC=gcc
> COLLECT_LTO_WRAPPER=c:/tdm-gcc-64/bin/../libexec/gcc/x86_64-w64-mingw32/4.8.1/lto-wrapper.exe
> Target: x86_64-w64-mingw32
> Configured with: ../../../src/gcc-4.8.1/configure
> --build=x86_64-w64-mingw32 --enable-targets=all --enable-lan
> guages=ada,c,c++,fortran,lto,objc,obj-c++ --enable-libgomp
> --enable-lto --enable-graphite --enable-cxx-flags=-
> DWINPTHREAD_STATIC --enable-libstdcxx-debug --enable-threads=posix
> --enable-version-specific-runtime-libs --en
> able-fully-dynamic-string --enable-libstdcxx-threads
> --enable-libstdcxx-time --with-gnu-ld --disable-werror --
> disable-nls --disable-win32-registry --prefix=/mingw64tdm
> --with-local-prefix=/mingw64tdm --with-pkgversion=td
> m64-2 --with-bugurl=http://tdm-gcc.tdragon.net/bugs
> Thread model: posix
> gcc version 4.8.1 (tdm64-2)

Since you're using MinGW, I believe the strtol implementation is
provided by Microsoft's runtime library, not by either gcc or glibc.  It
could be a bug in Microsoft's library, in MinGW's integration of gcc
with the library (I know it has problems with long double), or in your
test program.  I have my suspicions, but there's no point in
speculating.

I suggest trying my test program (see below) with the gcc you'reusing,
with MinGW, and with Microsoft's implementation.

If you have problems with "-4294967296" with 32-bit unsigned long, it's
likely you'd have similar problems with "-18446744073709551616" with
64-bit long.  Here's an updated test program that allows for both
possibilities.  With gcc, compiling with "-m32" (if supported) gives you
32-bit long.

#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <errno.h>
int main(void) {
    printf("ULONG_MAX = %lu (0x%lx)\n", ULONG_MAX, ULONG_MAX);

    errno = 0;
#if ULONG_MAX == 4294967295U
    unsigned long result = strtoul("-4294967296", NULL, 0);
#elif ULONG_MAX == 18446744073709551615U
    unsigned long result = strtoul("-18446744073709551616", NULL, 0);
#else
    #error "Unexpected value for ULONG_MAX"
#endif

    printf("result = %lu (0x%lx), errno = %d",
           result, result, errno);
    if (errno == ERANGE) {
        printf(" (ERANGE)");
    }
    putchar('\n');
}

On my system, with "-m32", I get:

    ULONG_MAX = 4294967295 (0xffffffff)
    result = 4294967295 (0xffffffff), errno = 34 (ERANGE)

Without "-m32", I get:

    ULONG_MAX = 18446744073709551615 (0xffffffffffffffff)
    result = 18446744073709551615 (0xffffffffffffffff), errno = 34 (ERANGE)

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

[toc] | [prev] | [next] | [standalone]


#58538

FromRobert Wessel <robertwessel2@yahoo.com>
Date2015-03-20 15:31 -0500
Message-ID<invoga5f9t9n6qovjcog4j75hd32r4ccnn@4ax.com>
In reply to#58524
On Fri, 20 Mar 2015 10:56:57 -0700, Keith Thompson <kst-u@mib.org>
wrote:

>jacob navia <jacob@jacob.remcomp.fr> writes:
>> d:\lcc\libc\test>gcc -v
>> Using built-in specs.
>> COLLECT_GCC=gcc
>> COLLECT_LTO_WRAPPER=c:/tdm-gcc-64/bin/../libexec/gcc/x86_64-w64-mingw32/4.8.1/lto-wrapper.exe
>> Target: x86_64-w64-mingw32
>> Configured with: ../../../src/gcc-4.8.1/configure
>> --build=x86_64-w64-mingw32 --enable-targets=all --enable-lan
>> guages=ada,c,c++,fortran,lto,objc,obj-c++ --enable-libgomp
>> --enable-lto --enable-graphite --enable-cxx-flags=-
>> DWINPTHREAD_STATIC --enable-libstdcxx-debug --enable-threads=posix
>> --enable-version-specific-runtime-libs --en
>> able-fully-dynamic-string --enable-libstdcxx-threads
>> --enable-libstdcxx-time --with-gnu-ld --disable-werror --
>> disable-nls --disable-win32-registry --prefix=/mingw64tdm
>> --with-local-prefix=/mingw64tdm --with-pkgversion=td
>> m64-2 --with-bugurl=http://tdm-gcc.tdragon.net/bugs
>> Thread model: posix
>> gcc version 4.8.1 (tdm64-2)
>
>Since you're using MinGW, I believe the strtol implementation is
>provided by Microsoft's runtime library, not by either gcc or glibc.  It
>could be a bug in Microsoft's library, in MinGW's integration of gcc
>with the library (I know it has problems with long double), or in your
>test program.  I have my suspicions, but there's no point in
>speculating.


You're almost certainly correct, this is (only) an MS C-lib problem. I
think mingw always uses MS's library, and as I mentioned, elsewhere,
all the glib-ish sources I've seen appear to do it correctly.

This would also explain why MSVC and GCC (as mingw) exhibit the same
problem.  In any event, the error is clear, and as I speculated, in
MS's source for strtoul.

I'm not going to post the source, since it's Copyright MS, but the
block that returns the results is in lines 190-221 of strtol.c
(MSVS2010/MSVC16), and does approximately:


        if (...no digits...)
        {
            (...)
            number = 0L;
        }
        else if (...overflow...)
        {
            errno = ERANGE;
            number = ULONG_MAX/-LONG_MIN/LONG_MAX, as appropriate;
        }

        ...store endptr as needed...

        if (flags & FL_NEG)
            /* negate result if there was a neg sign */
            number = (unsigned long)(-(long)number);

        return number;  


It does the negation even if it's setting ERANGE.  There either needs
to be a test for the ERANGE condition in the block where the negation
happens, or a return in the block where the ERANGE is set, but the
latter would also require setting endptr before the return.

[toc] | [prev] | [next] | [standalone]


#58522

Fromjacob navia <jacob@jacob.remcomp.fr>
Date2015-03-20 18:28 +0100
Message-ID<mehlba$aq1$2@speranza.aioe.org>
In reply to#58467
I filed a cbug report at the web site indicated by the gcc implementation

http://sourceforge.net/p/tdm-gcc/bugs/258/

Let's wait and see.

jacob

[toc] | [prev] | [next] | [standalone]


Page 2 of 3 — ← Prev page 1 [2] 3  Next page →

Back to top | Article view | comp.lang.c


csiph-web