lua-users home
lua-l archive

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


Hi David,

> When compiling Lua with the Lcc-Win32 compiler, I get the following
> warnings:
> ...
> Warning c:\lua-4.0\src\lib\lstrlib.c: 546  indexing array 542[512]
> out of bounds (512)
> 
> The above refer to the 'luaL_putchar' macro:
> 
> #define luaL_putchar(B,c) \
>   ((void)((B)->p < &(B)->buffer[LUAL_BUFFERSIZE] || luaL_prepbuffer
> (B)), \
>    (*(B)->p++ = (char)(c)))

The array element is not actually being accessed. The indexing is only
used to compute an address. ANSI C allows references to the position
"just after" the array's last element, so that the the code is indeed
correct. If you change the above to  LUAL_BUFFERSIZE-1, the code will
always waste the last byte of the array. Maybe you could change
&(B)->buffer[LUAL_BUFFERSIZE] to (B->buffer + LUAL_BUFFERSIZE) instead.
The change would have no effect other than possibly fooling the warning
generator.

> Warning c:\lua-4.0\src\lib\lstrlib.c: 384  possible usage of init
> before definition

Code inspection shows that the value will always be initialized before
use, since the while test condition has this side-effect when its first
part succeeds. But the compiler wouldn't know... 
You patch is ok, though, if you can't stand the warning. :-)

> Warning c:\lua-4.0\src\lib\liolib.c: 512  Different const qualifiers
...
> Warning c:\lua-4.0\src\lib\liolib.c: 547  Different const qualifiers
> I could not figure out why the above warnings were being generated,
> but I figured I'd pass them onto you anyway. :)

Those are because Lua's library functions receive and return (const char
*) values. Some stdio implementations do not declare their parameters to
be (const char *) even when the values are read-only. You can supress
the warnings for line 512, for example, by changing it to

static int io_rename (lua_State *L) {
  return pushresult(L, rename((char *) luaL_check_string(L, 1),
                    (char *) luaL_check_string(L, 2)) == 0);
}

Although I woudn't bother.

Regards,
Diego.