Re: Arrays oddities

  • From: Mike Pall <mike-1403@xxxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Mon, 31 Mar 2014 11:51:55 +0200

Alain Meunier wrote:
> So basically anything my bytes[5] may be lost if the system need that memory 
> space, right ?

Lost? No, it's a grave mistake to access out-of-bounds elements
and this may lead to crashes. Don't do it.

The FFI is like C: there's no hand-holding.

> Obviously it will not be the case with bytes[2] because it is in the bounds.

No, bytes[0] and bytes[1] are the only valid indexes.

I cannot recommend to use the FFI without a firm grasp of C's
memory model. E.g. zero-based indexing or the width of types
(an array of int cannot reasonably be called 'bytes').

> And  this code is realistic enough to be used in production.

Oh dear.

--Mike

Other related posts: