Boszormenyi Zoltan írta:
> Hi,
>
> my question is that what platform were these
> functions developed and tested?
>
> We have come across a value that fails a NOT NULL
> constraint upon INSERT under HP-UX/IA64, but not
> under x86-64 Linux. The value in question is
> 1.9999999999999998 assigned to a "double" variable.
> Under HP-UX/IA64, testing with risnull() from
> the application indeed returns true, but under
> Linux/x86-64 returns false.
>
> I will test rsetnull() results on real Informix under
> HP-UX/IA64.
>   

I have tested it under ESQL/C on HP-UX/ia64 and
this happened:
- rsetnull() on a double value creates
  FF FF FF FF FF FF FF FF
- the value causing the error above is
  3F FF FF FF FF FF FF FF

It seems that this function in ecpglib/misc.c has
an off-by-one bug as it's interpreted by the HP-UX CC:

static bool
_check(unsigned char *ptr, int length)
{
        for (; length > 0 && ptr[--length] == 0xff;);
        if (length <= 0)
                return true;
        return false;
}

I suspect that GCC does the "--length" after checking
"length > 0" and before checking the "ptr[...] == 0xff",
but HP CC does it before checking "length > 0".

The attached patch solves the problem.

Best regards,
Zoltán Böszörményi

-- 
Bible has answers for everything. Proof:
"But let your communication be, Yea, yea; Nay, nay: for whatsoever is more
than these cometh of evil." (Matthew 5:37) - basics of digital technology.
"May your kingdom come" - superficial description of plate tectonics

----------------------------------
Zoltán Böszörményi
Cybertec Schönig & Schönig GmbH
http://www.postgresql.at/

*** pgsql.4/src/interfaces/ecpg/ecpglib/misc.c.old	2009-11-19 19:50:38.000000000 +0100
--- pgsql.4/src/interfaces/ecpg/ecpglib/misc.c	2009-11-19 19:51:23.000000000 +0100
***************
*** 364,373 ****
  static bool
  _check(unsigned char *ptr, int length)
  {
! 	for (; length > 0 && ptr[--length] == 0xff;);
! 	if (length <= 0)
! 		return true;
! 	return false;
  }
  
  bool
--- 364,375 ----
  static bool
  _check(unsigned char *ptr, int length)
  {
! 	int	i;
! 	for (i = 0; i < length && ptr[i] == 0xff; i++)
! 		;
! 	if (i < length)
! 		return false;
! 	return true;
  }
  
  bool
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to