lua-users home
lua-l archive

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


> Patch to lua.c attached. Compiles warning-free as a Lua 5.2.4 patch but
> gives a warning for incompatible types on 5.3.4 that I can't fix. Still works,
> though.

> 261,262c261,264
> <   lua_getglobal(L, "require");
> <   lua_pushstring(L, name);
> ---
> >   char *eq = strchr(name,'=');
> >   lua_getglobal(L, "require");  
> >   if (eq==name) lua_pushstring(L, name);
> >   else lua_pushstring(L, eq+1);

The test 'eq==name' seems weird. Wouldn't it be true only when 'name'
starts with "="?


> 264,265c266,269
> <   if (status == LUA_OK)
> <     lua_setglobal(L, name);  /* global[name] = require return */
> ---
> >   if (status == LUA_OK) {
> >     if (eq==name) lua_setglobal(L, name);  /* global[name] = require return */
> >     else lua_setglobal(L, strndup(name,eq-name));       
> >   }

'strndup' is not ANSI, and it leaks memory when used like here.

-- Roberto