From: | jian he <jian(dot)universality(at)gmail(dot)com> |
---|---|
To: | Matthew Kim <matthewkmkim(at)gmail(dot)com> |
Cc: | Joseph Koshakow <koshy44(at)gmail(dot)com>, Nathan Bossart <nathandbossart(at)gmail(dot)com>, Alexander Lakhin <exclusion(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Andres Freund <andres(at)anarazel(dot)de> |
Subject: | Re: Remove dependence on integer wrapping |
Date: | 2024-08-09 01:01:27 |
Message-ID: | CACJufxHNwqoXoP91a-2D3NytrurTSK_+-hd+XeVCYAbk2F0Uhw@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Fri, Aug 9, 2024 at 6:16 AM Matthew Kim <matthewkmkim(at)gmail(dot)com> wrote:
>
> I've updated patch 0004 to check the return value of pg_mul_s32_overflow(). Since tm.tm_year overflowed, the error message is hardcoded.
>
--- a/src/backend/utils/adt/date.c
+++ b/src/backend/utils/adt/date.c
@@ -257,7 +257,10 @@ make_date(PG_FUNCTION_ARGS)
if (tm.tm_year < 0)
{
bc = true;
- tm.tm_year = -tm.tm_year;
+ if (pg_mul_s32_overflow(tm.tm_year, -1, &tm.tm_year))
+ ereport(ERROR,
+ (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
+ errmsg("date field value out of range")));
}
Should the error about integers be out of range?
SELECT make_date(-2147483648, 1, 1);
"-2147483648" is not an allowed integer.
\df make_date
List of functions
Schema | Name | Result data type | Argument data
types | Type
------------+-----------+------------------+------------------------------------------+------
pg_catalog | make_date | date | year integer, month
integer, day integer | func
From | Date | Subject | |
---|---|---|---|
Next Message | Melanie Plageman | 2024-08-09 01:02:15 | Re: Add LSN <-> time conversion functionality |
Previous Message | jian he | 2024-08-09 00:57:39 | Re: Detailed release notes |