lua-users home
lua-l archive

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

Which standard? In C/C++ or Lua?
May be some C implementations may fail, but these are certainly bad, excemt for saying that the block was not real located but is the original block still usable? I think it is even if the realloc returned a null. If this is not the case, then don't use the realloc from C, but only malloc, perform the memcpy after if it succeeds, and free the old block. That's what all decent C library should do. But then you need your own memory manager. Just a waste of time, consider changing your c library for another that will correctly handle block size reduction without ever failing if the original block pointer was valid

Le mar. 11 août 2020 à 04:10, Andrew Gierth <> a écrit :
>>>>> "Philippe" == Philippe Verdy <> writes:

 Philippe> I don't think thank shrinking or keeping the same size may
 Philippe> fail

It doesn't matter what you think. What matters is what the language
standards say, and what they say is that realloc() is permitted to fail
when shrinking a block. (Some realloc implementations never fail in that
case, but many in common use do.)