lua-users home
lua-l archive

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


On Fri, Dec 5, 2008 at 10:45 AM, Luiz Henrique de Figueiredo
<lhf@tecgraf.puc-rio.br> wrote:
>> Hi. I tried this with my build of Lua 5.1.4 which has api_check enabled
>> and it asserts in function 'doconcat' at the first lua_rawgeti. It seems
>> that it cannot grow the stack
>
> Sorry, I messed up the stack counts and also forgot a couple of lua_pop...
> Here is the corrected version.
> Thanks for spotting this.
> --lhf
>

This version incorrectly changes the value at index 2 to an empty
string (in unrope). This may cause memcpy to copy from a NULL pointer,
although my operating system's implementation of memcpy cowardly
avoids this. I suggest changing it to this:

  luaL_Buffer b;
  luaL_checktype(L,1,LUA_TTABLE);
  lua_settop(L,2);
  if (lua_isnoneornil(L,2)) {lua_pushliteral(L,""); lua_replace(L,2);}
  else luaL_typerror(2,"nil/string");
  lua_insert(L,1);
  /* ... */

I think there also may be a problem with the stack not being large
enough to accommodate the luaL_Buffer but I have not explored this
yet.

Cheers,

-- 
-Patrick Donnelly

"One of the lessons of history is that nothing is often a good thing
to do and always a clever thing to say."

-Will Durant