avr-libc-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-libc-dev] [bugs #11494] strtol() return wrong value in the unde


From: Dmitry K.
Subject: Re: [avr-libc-dev] [bugs #11494] strtol() return wrong value in the underflow case
Date: Wed, 12 Jan 2005 08:15:11 +1000
User-agent: KMail/1.5

On Tuesday 11 January 2005 08:51, Eric Weddington wrote:
>
> Follow-up Comment:
> In the patch for this bug, can you rewrite your typecasts using the types
> found in stdint.h? (for example uint32_t, uint16_t)
>
>
>
> That way it can start to be -mint8 compatible.

Hi.

My opinion about "-mint8 compatibility":

   Without -mint8 option, original (and patched) `strtol'
   return `long' value, that is clipped in bounds LONG_MIN
   and LONG_MAX.  Such, strtol("5000000000",0,0) must return
   2147483647.
      With -mint8 option, `strtol' must also return `long'
   value, clipped by LONG_MIN and LONG_MAX also.  But, due
   to reduced size of `long' (and reduced LONG_MAX, LONG_MIN),
   the result of strtol("5000000000",0,0) must be 32767.
      Such behavior agree, for example, glibc.  On computer
   with 64-bit long, result of strtol("5000000000",0,0) will
   be 5000000000.

In such sence, strtol (original and patched) work true with
any size of `long'.

But if anybody is needing a function, that must return value,
"at least as 32 bits", it is necessity to write another function,
with another name, like:
   int32_t strto32 (const char *, char **, int) .

Thanks.

P.S.  In patch #3618 (strtol optimization) second part of source
contain test for strtol with strings, like:
   { "2147483647", 0, 0x7fffffff, 0, 10 }
This test do not work with `-mint8' option and must be rewrited
with conditional compilation usage.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]