What problems may occur if the restriction(i.e. l_alloc should not fail when shrinking the block) is broken?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

What problems may occur if the restriction(i.e. l_alloc should not fail when shrinking the block) is broken?

孙世龙 sunshilong
Hi, list

As per the documentation(i.e.
https://www.lua.org/manual/5.3/manual.html#lua_Alloc),
which says [emphasise mine]:
This code assumes that realloc does not fail when shrinking a block.
(Although Standard C does not ensure this behavior, it seems to be a
safe assumption.)

Then a question arises:
What problems may occur if the restriction(i.e. l_alloc should not
fail when shrinking the block) is broken?

Thank you for your attention to this matter.
Best regards
Reply | Threaded
Open this post in threaded view
|

Re: What problems may occur if the restriction(i.e. l_alloc should not fail when shrinking the block) is broken?

Roberto Ierusalimschy
> What problems may occur if the restriction(i.e. l_alloc should not
> fail when shrinking the block) is broken?

The usual problems that occur when an assumption in some code is
wrong: Algorithms do not work as expected, which may leave the program
in some inconsistent state, which may result in crashes, memory leaks,
wrong results, etc. As an example, see the function luaH_resize in file
lgc.c and figure out what happens if the call after the comment "shrink
array" raises an error and interrupts the resize.

-- Roberto