lua-users home
lua-l archive

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



I am having crashes when attempting to use Lua 5.1 (source code from taken 3 Feb 2006). A field in L->ci->func->value appears to be uninitialised.


Is this a known bug or am I doing something stupid? The Lua compiler and console (luac.c and lua.c) code seems to work however it arrives at the index2adr call via a different code path during which the field appears to get correctly initialised. 


Thanks for the help,


D. Stockdale




Complete application code:


    #include <stdio.h>

    #include <lua.h>

    #include <lauxlib.h>

    #include <lualib.h>


    int main (int argc, char* argv[]) {


      lua_State *L = lua_open(); 



      luaopen_io(L);                // <-- Crashes in here             





      return 0;





Lua Sample.exe!index2adr(lua_State * L=0x00323d80, int idx=-10001)  Line 64 + 0xf         

Lua Sample.exe!lua_replace(lua_State * L=0x00323d80, int idx=-10001)  Line 203 + 0xd    

Lua Sample.exe!luaopen_io(lua_State * L=0x00323d80)  Line 513 + 0xe    

Lua Sample.exe!main()  Line 175 + 0x9  

Lua Sample.exe!mainCRTStartup()  Line 259 + 0x19        



Crash location:


static TValue *index2adr (lua_State *L, int idx) {

  if (idx > 0) {

    TValue *o = L->base + (idx - 1);

    api_check(L, idx <= L->ci->top - L->base);

    if (o >= L->top) return cast(TValue *, luaO_nilobject);

    else return o;


  else if (idx > LUA_REGISTRYINDEX) {

    api_check(L, idx != 0 && -idx <= L->top - L->base);

    return L->top + idx;


  else switch (idx) {  /* pseudo-indices */

    case LUA_REGISTRYINDEX: return registry(L);


      Closure *func = curr_func(L);   // *** THIS RETURNS AN INVALID POINTER ***

      sethvalue(L, &L->env, func->c.env); //&(o)->value.gc->cl)

      return &L->env;


    case LUA_GLOBALSINDEX: return gt(L);

    default: {

      Closure *func = curr_func(L);

      idx = LUA_GLOBALSINDEX - idx;

      return (idx <= func->c.nupvalues)

                ? &func->c.upvalue[idx-1]

                : cast(TValue *, luaO_nilobject);





The contents of this e-mail and any attachments are confidential to the intended recipient and may also be legally privileged. Unless you are the named addressee (or authorised to receive for the addressee) of this email you may not copy, disclose or distribute it to anyone else.

If you have received this email in error, please notify us immediately by e-mail on and then delete the email and any copies. The SEGA Group have made all reasonable efforts to ensure that this e-mail and any attached documents or software are free from software viruses, but it is the recipient's responsibility to confirm this.