[Lazarus] SEGFAULT: difference between pointer and dynarray?

Sven Barth pascaldragon at googlemail.com
Sun Dec 30 14:34:36 CET 2012


On 30.12.2012 05:30, leledumbo wrote:
> Program received signal SIGSEGV, Segmentation fault.
> 0xb7e386d2 in ?? () from /lib/i386-linux-gnu/libc.so.6
> (gdb) bt
> #0  0xb7e386d2 in ?? () from /lib/i386-linux-gnu/libc.so.6
> #1  0xb7fa2d12 in ?? () from /usr/lib/i386-linux-gnu/liblua5.2.so.0
> #2  0xb7f95f09 in lua_setfield () from
> /usr/lib/i386-linux-gnu/liblua5.2.so.0
> #3  0xb7fa9a9a in luaL_setfuncs () from
> /usr/lib/i386-linux-gnu/liblua5.2.so.0
> #4  0x08066821 in LUAL_SETFUNCS (L=0x8071008, LR=..., highLR=1, NUP=0) at
> lua52.pas:835
> #5  0x080669e4 in LUAL_NEWLIB (L=0x8071008, LR=..., highLR=1) at
> lua52.pas:859
> #6  0x0804a3ea in main () at test.pas:31
>
> As you can see, the pointer changes when you pass an open array into another
> function expecting open array, even when static array is used (I've tried
> that one too). So, somebody with enough compiler knowledge should analyze
> this. Maybe you should create a bug report.

If the code of that lua52.pas is the one available here: 
http://lua-users.org/files/wiki_insecure/lua52.pas the error is 
understandable if one looks at the luaL_newlib function (the array 
overload):

=== source begin ===

procedure luaL_newlib(L: Plua_State; lr: array of luaL_Reg);
begin
    luaL_newlibtable(L, lr);
    luaL_setfuncs(L, @lr, 0);
end;

=== source end ===

The address of the open array parameter is passed, not the array to the 
first element. If you change the luaL_setfuncs call to

=== source begin ===

luaL_setfuncs(L, @lr[0], 0);

=== source end ===

it should work...

Regards,
Sven




More information about the Lazarus mailing list