lua-users home
lua-l archive

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


  I experience segfault when try to run following code snippet:
int main(int argc, char *argv[]) {
  lua_State *L = lua_open();
  char buf[5]; int i;

  for(i = 1; i < 50; ++i) {
    sprintf(buf, "%d", i);
    lua_pushstring(L, buf);


  And here is the valgrind output (stripped):

==5372== Invalid write of size 4
==5372==    at 0x8048EFA: lua_pushlstring (lapi.c:408)
==5372==    by 0x8048F72: lua_pushstring (lapi.c:418)
==5372==    by 0x80486D6: main (luatest.c:11)
==5372==  Address 0x259A43A4 is 0 bytes after a block of size 540 alloc'd
==5372==    at 0x25985298: malloc (vg_replace_malloc.c:130)
==5372==    by 0x25985C3B: realloc (vg_replace_malloc.c:188)
==5372==    by 0x804C891: luaM_realloc (lmem.c:77)
==5372==    by 0x804F08B: stack_init (lstate.c:65)
==5372==    by 0x804F1D6: f_luaopen (lstate.c:111)
==5372==    by 0x804A8F3: luaD_rawrunprotected (ldo.c:88)
==5372==    by 0x804F458: lua_open (lstate.c:189)
==5372==    by 0x80486A0: main (luatest.c:6)

  Antero Vipunen.