lua-users home
lua-l archive

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


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 */
}