Faults on Raspberry Pi and PPC Linux with Lua 5.4.0 RC 5 in lobjects.c/str2num

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Faults on Raspberry Pi and PPC Linux with Lua 5.4.0 RC 5 in lobjects.c/str2num

Alexander Walz
Hi,

when merging Lua 5.4 code into a Lua 5.1 fork, I noticed problems on my
Raspberry Pi 4 and also on Power PC with lobjects.c/str2num returning
2^32 with integral arguments that are within its range, when reading
values from files.

I just changed the code as depicted below which works fine.

Yours,

Alex


lobjects.c

/* On PowerPC and ARM l_str2int does seem to not work correctly and
returns wrong results; OS/2, DOS, Windows, x86 Linux &
    x86 Mac OS X are fine, however. */
#if (defined(__i386__) || defined(__x86_64__))
#define ACTIVATE   1
#else
#define ACTIVATE   0
#endif

size_t luaO_str2num (const char *s, TValue *o) {
   lua_Integer i; lua_Number n;
   const char *e;
   if (ACTIVATE && ((e = l_str2int(s, &i)) != NULL)) { /* try as an
integer */
     setnvalue(o, i);
   }
   else if ((e = l_str2d(s, &n)) != NULL) {  /* else try as a float */
     setnvalue(o, n);
   }
   else
     return 0;  /* conversion failed */
   return (e - s) + 1;  /* success; return string size */
}

Reply | Threaded
Open this post in threaded view
|

Re: Faults on Raspberry Pi and PPC Linux with Lua 5.4.0 RC 5 in lobjects.c/str2num

Andrew Gierth
>>>>> "Alexander" == Alexander Walz <[hidden email]> writes:

 Alexander> Hi,

 Alexander> when merging Lua 5.4 code into a Lua 5.1 fork, I noticed
 Alexander> problems on my Raspberry Pi 4 and also on Power PC with
 Alexander> lobjects.c/str2num returning 2^32 with integral arguments
 Alexander> that are within its range, when reading values from files.

What values, and in what way did you modify l_str2int? And what types
are you using for lua_Integer, lua_Unsigned etc? It all works fine for
me on my ARM systems.

(A common error that shows up on ARM platforms is if you try and cast a
negative float value to an unsigned integer; this is undefined in C.)

--
Andrew.
Reply | Threaded
Open this post in threaded view
|

Re: Faults on Raspberry Pi and PPC Linux with Lua 5.4.0 RC 5 in lobjects.c/str2num

Alexander Walz
Adrew,

exactly that: trying to cast a negative integral.

I will now remain silent.

Sorry,

Alex

Andrew Gierth wrote:

>>>>>> "Alexander" == Alexander Walz <[hidden email]> writes:
>   Alexander> Hi,
>
>   Alexander> when merging Lua 5.4 code into a Lua 5.1 fork, I noticed
>   Alexander> problems on my Raspberry Pi 4 and also on Power PC with
>   Alexander> lobjects.c/str2num returning 2^32 with integral arguments
>   Alexander> that are within its range, when reading values from files.
>
> What values, and in what way did you modify l_str2int? And what types
> are you using for lua_Integer, lua_Unsigned etc? It all works fine for
> me on my ARM systems.
>
> (A common error that shows up on ARM platforms is if you try and cast a
> negative float value to an unsigned integer; this is undefined in C.)
>
Reply | Threaded
Open this post in threaded view
|

Re: Faults on Raspberry Pi and PPC Linux with Lua 5.4.0 RC 5 in lobjects.c/str2num

Roberto Ierusalimschy
In reply to this post by Alexander Walz
> when merging Lua 5.4 code into a Lua 5.1 fork, I noticed problems on my
> Raspberry Pi 4 and also on Power PC with lobjects.c/str2num returning
> 2^32 with integral arguments that are within its range, when reading values
> from files.

Could you describe more precisely the problem you are trying to solve,
such as a piece of code giving an unexpected result?

-- Roberto