Re: BUG #1608: integer negative limit in plpgsql function arguments

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Paul Edwards <paul(at)allinea(dot)com>
Cc: pgsql-bugs(at)postgreSQL(dot)org
Subject: Re: BUG #1608: integer negative limit in plpgsql function arguments
Date: 2005-04-23 18:37:20
Message-ID: 13095.1114281440@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

I wrote:
> You're right, we do cheat a little on negative numeric constants --- I
> had forgotten about the doNegate() hack in gram.y. We could conceivably
> fix it to cheat some more. Specifically it looks like make_const() in
> parse_node.c could check for the possibility that a T_Float fits in INT4
> --- which would happen only for the case of -2147483648, since any
> smaller absolute value would have been T_Integer to start with.

I've applied the attached patch to CVS HEAD. I'm not going to risk
back-patching this, but feel free to use the patch locally if it's
important to you.

regards, tom lane

*** src/backend/parser/parse_node.c.orig Fri Dec 31 17:45:55 2004
--- src/backend/parser/parse_node.c Sat Apr 23 14:28:03 2005
***************
*** 304,314 ****
/* could be an oversize integer as well as a float ... */
if (scanint8(strVal(value), true, &val64))
{
! val = Int64GetDatum(val64);

! typeid = INT8OID;
! typelen = sizeof(int64);
! typebyval = false; /* XXX might change someday */
}
else
{
--- 304,331 ----
/* could be an oversize integer as well as a float ... */
if (scanint8(strVal(value), true, &val64))
{
! /*
! * It might actually fit in int32. Probably only INT_MIN can
! * occur, but we'll code the test generally just to be sure.
! */
! int32 val32 = (int32) val64;

! if (val64 == (int64) val32)
! {
! val = Int32GetDatum(val32);
!
! typeid = INT4OID;
! typelen = sizeof(int32);
! typebyval = true;
! }
! else
! {
! val = Int64GetDatum(val64);
!
! typeid = INT8OID;
! typelen = sizeof(int64);
! typebyval = false; /* XXX might change someday */
! }
}
else
{

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2005-04-23 21:18:16 Re: BUG #1583: Locale problem
Previous Message Tom Lane 2005-04-23 17:56:58 Re: empty array can crash backend using int_array_enum from contrib.