Re: more problems with the money type

From: Andrew Chernow <ac(at)esilo(dot)com>
To: "D'Arcy J(dot)M(dot) Cain" <darcy(at)druid(dot)net>
Cc: Merlin Moncure <mmoncure(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: more problems with the money type
Date: 2007-08-21 00:20:53
Message-ID: 46CA2FE5.9030305@esilo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Division segfaults server as well - SELECT '3'::money / 2 - for the same reason
multiplication did.

/* cash_div_int4()
* Divide cash by 4-byte integer.
*
*/
Datum
cash_div_int4(PG_FUNCTION_ARGS)
{
Cash c = PG_GETARG_CASH(0);
int64 i = PG_GETARG_INT64(1);
Cash result;

if (i == 0)
ereport(ERROR,
(errcode(ERRCODE_DIVISION_BY_ZERO),
errmsg("division by zero")));

result = rint(c / i);

PG_RETURN_CASH(result);
}

Should be "int32 i = PG_GETARG_INT32(1);" just like cash_mul_int4().

Andrew

Andrew Chernow wrote:
> >>> What does "SELECT 2 * '3'::money;" do?
> That works.
>
> >>try changing "64" to "32" in the function cash_mul_int4
> That also worked.
>
> Datum
> cash_mul_int4(PG_FUNCTION_ARGS)
> {
> Cash c = PG_GETARG_CASH(0);
> /*int64 i = PG_GETARG_INT64(1);*/
> int32 i = PG_GETARG_INT32(1);
> Cash result;
>
> result = c * i;
> PG_RETURN_CASH(result);
> }
>
> See submitted patch that fixes cash_send and cash_recv as well.
> Patch: http://archives.postgresql.org/pgsql-patches/2007-08/msg00117.php
>
> Andrew
>
>
> D'Arcy J.M. Cain wrote:
>> On Mon, 20 Aug 2007 17:32:42 -0400
>> "Merlin Moncure" <mmoncure(at)gmail(dot)com> wrote:
>>> while playing with the binary transport of the money type we found
>>> another bug. The following code segfaults the server on 8.3cvs:
>>>
>>> select '3'::money * 2;
>>
>> What does "SELECT 2 * '3'::money;" do? If that works try changing "64"
>> to "32" in the function cash_mul_int4. Let me know and I will commit
>> the fix as soon as I get CVS access again.
>>
>>> aside: since the money type was deprecated, why was it bumped to 64
>>> bits?
>>
>> See the archives.
>>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
> message can get through to the mailing list cleanly
>
>

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tatsuo Ishii 2007-08-21 00:52:47 Developer's profile
Previous Message Andrew Chernow 2007-08-21 00:00:47 Re: more problems with the money type