lua-users home
lua-l archive

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


It was thus said that the Great Sean Conner once stated:
> 
>   Okay, I'm using Lua 5.1.5 (and all the patches [1]) and for the life of
> me, I can't figure out what I'm doing wrong.

  I have figured out what I'm doing wrong.  And yes, it is an issue with
64bit Linux (or 64b systems in general).  The problematic bit of code first:

	lua_Number ival;

	if (lua_isnumber(L,3))
	  ival = lua_tonumber(L,3);

	/* SNIP */

	if (ival >= RLIM_INFINITY)
	  ival = RLIM_INFINITY;
  
	limit.rlim_cur = ival;

  This gets translated to:

	lua_Number ival;

	if (lua_isnumber(L,3))
	  ival = lua_tonumber(L,3);

	/* SNIP */

	if (ival >= ((unsigned long int)(~0UL)))
	  ival = ((unsigned long int)(~0UL));
  
	limit.rlim_cur = ival;
	
  On the 64bit system in question, an unsigned long is 64 bits in size.  But
ival is of type double (ultimately).  But, only integer quantities up to
2^53 (or is it 2^52?  It's somewhere around that range) are safely stored as
integers in doubles, so the line

	limit.rlim_cur = ival;

is the problem!  The value in ival isn't representable as an integer (well,
techinically, it is on a 64-bit system, but a double can only store integers
up to 2^53 (or thereabouts)) the value of 0 is stored into limit.rlim_cur,
thus the root cause of the problems I've been fighting for the past two
days.

  Sigh.

  Now that I know the issue, I can fix the bug.

  -spc