From 28dabaab2f57d05d87ff3935f562c63f1026c2f5 Mon Sep 17 00:00:00 2001 From: Derick Rethans Date: Thu, 23 Nov 2023 16:06:00 +0000 Subject: [PATCH 1/2] Import timelib 2022.10 --- ext/date/lib/parse_date.c | 233 +++++++++++++++++++------------------ ext/date/lib/parse_date.re | 25 ++-- ext/date/lib/timelib.c | 24 ++-- ext/date/lib/timelib.h | 6 +- 4 files changed, 159 insertions(+), 129 deletions(-) diff --git a/ext/date/lib/parse_date.c b/ext/date/lib/parse_date.c index 0b19c4fa4e9..a53fdc21547 100644 --- a/ext/date/lib/parse_date.c +++ b/ext/date/lib/parse_date.c @@ -1,4 +1,4 @@ -/* Generated by re2c 1.0.3 on Thu Aug 3 09:42:12 2023 */ +/* Generated by re2c 1.0.3 on Thu Nov 23 16:02:28 2023 */ #line 1 "ext/date/lib/parse_date.re" /* * The MIT License (MIT) @@ -713,6 +713,17 @@ static const timelib_relunit* timelib_lookup_relunit(const char **ptr) return value; } +static void add_with_overflow(Scanner *s, timelib_sll *e, timelib_sll amount, int multiplier) +{ +#if defined(__has_builtin) && __has_builtin(__builtin_saddll_overflow) + if (__builtin_saddll_overflow(*e, amount * multiplier, e)) { + add_error(s, TIMELIB_ERR_NUMBER_OUT_OF_RANGE, "Number out of range"); + } +#else + *e += (amount * multiplier); +#endif +} + /** * The time_part parameter is a flag. It can be TIMELIB_TIME_PART_KEEP in case * the time portion should not be reset to midnight, or @@ -728,13 +739,13 @@ static void timelib_set_relative(const char **ptr, timelib_sll amount, int behav } switch (relunit->unit) { - case TIMELIB_MICROSEC: s->time->relative.us += amount * relunit->multiplier; break; - case TIMELIB_SECOND: s->time->relative.s += amount * relunit->multiplier; break; - case TIMELIB_MINUTE: s->time->relative.i += amount * relunit->multiplier; break; - case TIMELIB_HOUR: s->time->relative.h += amount * relunit->multiplier; break; - case TIMELIB_DAY: s->time->relative.d += amount * relunit->multiplier; break; - case TIMELIB_MONTH: s->time->relative.m += amount * relunit->multiplier; break; - case TIMELIB_YEAR: s->time->relative.y += amount * relunit->multiplier; break; + case TIMELIB_MICROSEC: add_with_overflow(s, &s->time->relative.us, amount, relunit->multiplier); break; + case TIMELIB_SECOND: add_with_overflow(s, &s->time->relative.s, amount, relunit->multiplier); break; + case TIMELIB_MINUTE: add_with_overflow(s, &s->time->relative.i, amount, relunit->multiplier); break; + case TIMELIB_HOUR: add_with_overflow(s, &s->time->relative.h, amount, relunit->multiplier); break; + case TIMELIB_DAY: add_with_overflow(s, &s->time->relative.d, amount, relunit->multiplier); break; + case TIMELIB_MONTH: add_with_overflow(s, &s->time->relative.m, amount, relunit->multiplier); break; + case TIMELIB_YEAR: add_with_overflow(s, &s->time->relative.y, amount, relunit->multiplier); break; case TIMELIB_WEEKDAY: TIMELIB_HAVE_WEEKDAY_RELATIVE(); @@ -1003,11 +1014,11 @@ static int scan(Scanner *s, timelib_tz_get_wrapper tz_get_wrapper) std: s->tok = cursor; s->len = 0; -#line 1136 "ext/date/lib/parse_date.re" +#line 1147 "ext/date/lib/parse_date.re" -#line 1011 "" +#line 1022 "" { YYCTYPE yych; unsigned int yyaccept = 0; @@ -1188,23 +1199,23 @@ yy2: YYDEBUG(2, *YYCURSOR); ++YYCURSOR; YYDEBUG(3, *YYCURSOR); -#line 1969 "ext/date/lib/parse_date.re" +#line 1980 "ext/date/lib/parse_date.re" { s->pos = cursor; s->line++; goto std; } -#line 1197 "" +#line 1208 "" yy4: YYDEBUG(4, *YYCURSOR); ++YYCURSOR; yy5: YYDEBUG(5, *YYCURSOR); -#line 1975 "ext/date/lib/parse_date.re" +#line 1986 "ext/date/lib/parse_date.re" { add_error(s, TIMELIB_ERR_UNEXPECTED_CHARACTER, "Unexpected character"); goto std; } -#line 1208 "" +#line 1219 "" yy6: YYDEBUG(6, *YYCURSOR); yyaccept = 0; @@ -1219,11 +1230,11 @@ yy6: if (yych <= '9') goto yy58; yy8: YYDEBUG(8, *YYCURSOR); -#line 1964 "ext/date/lib/parse_date.re" +#line 1975 "ext/date/lib/parse_date.re" { goto std; } -#line 1227 "" +#line 1238 "" yy9: YYDEBUG(9, *YYCURSOR); yych = *++YYCURSOR; @@ -1257,11 +1268,11 @@ yy11: YYDEBUG(11, *YYCURSOR); ++YYCURSOR; YYDEBUG(12, *YYCURSOR); -#line 1959 "ext/date/lib/parse_date.re" +#line 1970 "ext/date/lib/parse_date.re" { goto std; } -#line 1265 "" +#line 1276 "" yy13: YYDEBUG(13, *YYCURSOR); yyaccept = 1; @@ -1762,7 +1773,7 @@ yy19: } yy20: YYDEBUG(20, *YYCURSOR); -#line 1874 "ext/date/lib/parse_date.re" +#line 1885 "ext/date/lib/parse_date.re" { int tz_not_found; DEBUG_OUTPUT("tzcorrection | tz"); @@ -1776,7 +1787,7 @@ yy20: TIMELIB_DEINIT; return TIMELIB_TIMEZONE; } -#line 1780 "" +#line 1791 "" yy21: YYDEBUG(21, *YYCURSOR); yych = *++YYCURSOR; @@ -3581,7 +3592,7 @@ yy80: } yy81: YYDEBUG(81, *YYCURSOR); -#line 1621 "ext/date/lib/parse_date.re" +#line 1632 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("datenoyearrev"); TIMELIB_INIT; @@ -3592,7 +3603,7 @@ yy81: TIMELIB_DEINIT; return TIMELIB_DATE_TEXT; } -#line 3596 "" +#line 3607 "" yy82: YYDEBUG(82, *YYCURSOR); yych = *++YYCURSOR; @@ -4107,7 +4118,7 @@ yy112: } if (yych == '.') goto yy289; YYDEBUG(114, *YYCURSOR); -#line 1196 "ext/date/lib/parse_date.re" +#line 1207 "ext/date/lib/parse_date.re" { timelib_ull i; @@ -4132,7 +4143,7 @@ yy112: TIMELIB_DEINIT; return TIMELIB_RELATIVE; } -#line 4136 "" +#line 4147 "" yy115: YYDEBUG(115, *YYCURSOR); ++YYCURSOR; @@ -5858,7 +5869,7 @@ yy176: } yy177: YYDEBUG(177, *YYCURSOR); -#line 1362 "ext/date/lib/parse_date.re" +#line 1373 "ext/date/lib/parse_date.re" { int tz_not_found; DEBUG_OUTPUT("timetiny24 | timeshort24 | timelong24 | iso8601long"); @@ -5885,7 +5896,7 @@ yy177: TIMELIB_DEINIT; return TIMELIB_TIME24_WITH_ZONE; } -#line 5889 "" +#line 5900 "" yy178: YYDEBUG(178, *YYCURSOR); yyaccept = 4; @@ -6914,7 +6925,7 @@ yy223: } yy224: YYDEBUG(224, *YYCURSOR); -#line 1456 "ext/date/lib/parse_date.re" +#line 1467 "ext/date/lib/parse_date.re" { int length = 0; DEBUG_OUTPUT("americanshort | american"); @@ -6929,7 +6940,7 @@ yy224: TIMELIB_DEINIT; return TIMELIB_AMERICAN; } -#line 6933 "" +#line 6944 "" yy225: YYDEBUG(225, *YYCURSOR); yyaccept = 5; @@ -7172,7 +7183,7 @@ yy250: if (yych <= '9') goto yy431; yy251: YYDEBUG(251, *YYCURSOR); -#line 1538 "ext/date/lib/parse_date.re" +#line 1549 "ext/date/lib/parse_date.re" { int length = 0; DEBUG_OUTPUT("datefull"); @@ -7186,7 +7197,7 @@ yy251: TIMELIB_DEINIT; return TIMELIB_DATE_FULL; } -#line 7190 "" +#line 7201 "" yy252: YYDEBUG(252, *YYCURSOR); yyaccept = 3; @@ -7300,7 +7311,7 @@ yy259: if (yych == 'e') goto yy440; yy260: YYDEBUG(260, *YYCURSOR); -#line 1943 "ext/date/lib/parse_date.re" +#line 1954 "ext/date/lib/parse_date.re" { timelib_ull i; DEBUG_OUTPUT("relative"); @@ -7315,7 +7326,7 @@ yy260: TIMELIB_DEINIT; return TIMELIB_RELATIVE; } -#line 7319 "" +#line 7330 "" yy261: YYDEBUG(261, *YYCURSOR); yych = *++YYCURSOR; @@ -7761,7 +7772,7 @@ yy289: if (yych <= '9') goto yy471; yy290: YYDEBUG(290, *YYCURSOR); -#line 1222 "ext/date/lib/parse_date.re" +#line 1233 "ext/date/lib/parse_date.re" { timelib_sll i; timelib_ull us; @@ -7800,7 +7811,7 @@ yy290: TIMELIB_DEINIT; return TIMELIB_RELATIVE; } -#line 7804 "" +#line 7815 "" yy291: YYDEBUG(291, *YYCURSOR); yych = *++YYCURSOR; @@ -7825,7 +7836,7 @@ yy292: } yy293: YYDEBUG(293, *YYCURSOR); -#line 1784 "ext/date/lib/parse_date.re" +#line 1795 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("ago"); TIMELIB_INIT; @@ -7845,7 +7856,7 @@ yy293: TIMELIB_DEINIT; return TIMELIB_AGO; } -#line 7849 "" +#line 7860 "" yy294: YYDEBUG(294, *YYCURSOR); yyaccept = 7; @@ -7884,7 +7895,7 @@ yy294: } yy295: YYDEBUG(295, *YYCURSOR); -#line 1864 "ext/date/lib/parse_date.re" +#line 1875 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("monthtext"); TIMELIB_INIT; @@ -7893,7 +7904,7 @@ yy295: TIMELIB_DEINIT; return TIMELIB_DATE_TEXT; } -#line 7897 "" +#line 7908 "" yy296: YYDEBUG(296, *YYCURSOR); yyaccept = 7; @@ -8468,7 +8479,7 @@ yy314: } yy315: YYDEBUG(315, *YYCURSOR); -#line 1805 "ext/date/lib/parse_date.re" +#line 1816 "ext/date/lib/parse_date.re" { const timelib_relunit* relunit; DEBUG_OUTPUT("daytext"); @@ -8485,7 +8496,7 @@ yy315: TIMELIB_DEINIT; return TIMELIB_WEEKDAY; } -#line 8489 "" +#line 8500 "" yy316: YYDEBUG(316, *YYCURSOR); yych = *++YYCURSOR; @@ -8753,7 +8764,7 @@ yy324: } yy325: YYDEBUG(325, *YYCURSOR); -#line 1607 "ext/date/lib/parse_date.re" +#line 1618 "ext/date/lib/parse_date.re" { int length = 0; DEBUG_OUTPUT("datetextual | datenoyear"); @@ -8766,7 +8777,7 @@ yy325: TIMELIB_DEINIT; return TIMELIB_DATE_TEXT; } -#line 8770 "" +#line 8781 "" yy326: YYDEBUG(326, *YYCURSOR); yyaccept = 10; @@ -9460,7 +9471,7 @@ yy350: } yy351: YYDEBUG(351, *YYCURSOR); -#line 1153 "ext/date/lib/parse_date.re" +#line 1164 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("now"); TIMELIB_INIT; @@ -9468,7 +9479,7 @@ yy351: TIMELIB_DEINIT; return TIMELIB_RELATIVE; } -#line 9472 "" +#line 9483 "" yy352: YYDEBUG(352, *YYCURSOR); yyaccept = 2; @@ -10971,7 +10982,7 @@ yy419: } yy420: YYDEBUG(420, *YYCURSOR); -#line 1390 "ext/date/lib/parse_date.re" +#line 1401 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("gnunocolon"); TIMELIB_INIT; @@ -10993,7 +11004,7 @@ yy420: TIMELIB_DEINIT; return TIMELIB_GNU_NOCOLON; } -#line 10997 "" +#line 11008 "" yy421: YYDEBUG(421, *YYCURSOR); yyaccept = 13; @@ -11074,7 +11085,7 @@ yy421: } yy422: YYDEBUG(422, *YYCURSOR); -#line 1775 "ext/date/lib/parse_date.re" +#line 1786 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("year4"); TIMELIB_INIT; @@ -11082,7 +11093,7 @@ yy422: TIMELIB_DEINIT; return TIMELIB_CLF; } -#line 11086 "" +#line 11097 "" yy423: YYDEBUG(423, *YYCURSOR); yyaccept = 3; @@ -11689,7 +11700,7 @@ yy456: YYDEBUG(456, *YYCURSOR); ++YYCURSOR; YYDEBUG(457, *YYCURSOR); -#line 1324 "ext/date/lib/parse_date.re" +#line 1335 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("timetiny12 | timeshort12 | timelong12"); TIMELIB_INIT; @@ -11706,7 +11717,7 @@ yy456: TIMELIB_DEINIT; return TIMELIB_TIME12; } -#line 11710 "" +#line 11721 "" yy458: YYDEBUG(458, *YYCURSOR); yych = *++YYCURSOR; @@ -13033,7 +13044,7 @@ yy525: } yy526: YYDEBUG(526, *YYCURSOR); -#line 1162 "ext/date/lib/parse_date.re" +#line 1173 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("noon"); TIMELIB_INIT; @@ -13044,7 +13055,7 @@ yy526: TIMELIB_DEINIT; return TIMELIB_RELATIVE; } -#line 13048 "" +#line 13059 "" yy527: YYDEBUG(527, *YYCURSOR); yyaccept = 2; @@ -14090,7 +14101,7 @@ yy566: } yy567: YYDEBUG(567, *YYCURSOR); -#line 1524 "ext/date/lib/parse_date.re" +#line 1535 "ext/date/lib/parse_date.re" { int length = 0; DEBUG_OUTPUT("gnudateshort"); @@ -14103,7 +14114,7 @@ yy567: TIMELIB_DEINIT; return TIMELIB_ISO_DATE; } -#line 14107 "" +#line 14118 "" yy568: YYDEBUG(568, *YYCURSOR); yyaccept = 15; @@ -14554,7 +14565,7 @@ yy599: } yy600: YYDEBUG(600, *YYCURSOR); -#line 1593 "ext/date/lib/parse_date.re" +#line 1604 "ext/date/lib/parse_date.re" { int length = 0; DEBUG_OUTPUT("datenodayrev"); @@ -14567,7 +14578,7 @@ yy600: TIMELIB_DEINIT; return TIMELIB_DATE_NO_DAY; } -#line 14571 "" +#line 14582 "" yy601: YYDEBUG(601, *YYCURSOR); yych = *++YYCURSOR; @@ -15942,7 +15953,7 @@ yy696: YYDEBUG(696, *YYCURSOR); ++YYCURSOR; YYDEBUG(697, *YYCURSOR); -#line 1579 "ext/date/lib/parse_date.re" +#line 1590 "ext/date/lib/parse_date.re" { int length = 0; DEBUG_OUTPUT("datenoday"); @@ -15955,7 +15966,7 @@ yy696: TIMELIB_DEINIT; return TIMELIB_DATE_NO_DAY; } -#line 15959 "" +#line 15970 "" yy698: YYDEBUG(698, *YYCURSOR); yych = *++YYCURSOR; @@ -16516,7 +16527,7 @@ yy721: } yy722: YYDEBUG(722, *YYCURSOR); -#line 1174 "ext/date/lib/parse_date.re" +#line 1185 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("midnight | today"); TIMELIB_INIT; @@ -16525,7 +16536,7 @@ yy722: TIMELIB_DEINIT; return TIMELIB_RELATIVE; } -#line 16529 "" +#line 16540 "" yy723: YYDEBUG(723, *YYCURSOR); yych = *++YYCURSOR; @@ -16835,7 +16846,7 @@ yy738: if (yych <= '9') goto yy897; yy739: YYDEBUG(739, *YYCURSOR); -#line 1565 "ext/date/lib/parse_date.re" +#line 1576 "ext/date/lib/parse_date.re" { int length = 0; DEBUG_OUTPUT("pointed date YY"); @@ -16848,7 +16859,7 @@ yy739: TIMELIB_DEINIT; return TIMELIB_DATE_FULL_POINTED; } -#line 16852 "" +#line 16863 "" yy740: YYDEBUG(740, *YYCURSOR); yyaccept = 15; @@ -16960,7 +16971,7 @@ yy751: } yy752: YYDEBUG(752, *YYCURSOR); -#line 1510 "ext/date/lib/parse_date.re" +#line 1521 "ext/date/lib/parse_date.re" { int length = 0; DEBUG_OUTPUT("gnudateshorter"); @@ -16973,7 +16984,7 @@ yy752: TIMELIB_DEINIT; return TIMELIB_ISO_DATE; } -#line 16977 "" +#line 16988 "" yy753: YYDEBUG(753, *YYCURSOR); yyaccept = 18; @@ -17222,7 +17233,7 @@ yy776: } yy777: YYDEBUG(777, *YYCURSOR); -#line 1436 "ext/date/lib/parse_date.re" +#line 1447 "ext/date/lib/parse_date.re" { int tz_not_found; DEBUG_OUTPUT("iso8601nocolon"); @@ -17241,7 +17252,7 @@ yy777: TIMELIB_DEINIT; return TIMELIB_ISO_NOCOLON; } -#line 17245 "" +#line 17256 "" yy778: YYDEBUG(778, *YYCURSOR); yyaccept = 19; @@ -18469,7 +18480,7 @@ yy848: } yy849: YYDEBUG(849, *YYCURSOR); -#line 1913 "ext/date/lib/parse_date.re" +#line 1924 "ext/date/lib/parse_date.re" { int tz_not_found; DEBUG_OUTPUT("dateshortwithtimeshort | dateshortwithtimelong | dateshortwithtimelongtz"); @@ -18498,7 +18509,7 @@ yy849: TIMELIB_DEINIT; return TIMELIB_SHORTDATE_WITH_TIME; } -#line 18502 "" +#line 18513 "" yy850: YYDEBUG(850, *YYCURSOR); yyaccept = 20; @@ -19542,7 +19553,7 @@ yy925: } yy926: YYDEBUG(926, *YYCURSOR); -#line 1671 "ext/date/lib/parse_date.re" +#line 1682 "ext/date/lib/parse_date.re" { int length = 0; DEBUG_OUTPUT("pgydotd"); @@ -19555,7 +19566,7 @@ yy926: TIMELIB_DEINIT; return TIMELIB_PG_YEARDAY; } -#line 19559 "" +#line 19570 "" yy927: YYDEBUG(927, *YYCURSOR); yyaccept = 21; @@ -19809,7 +19820,7 @@ yy941: if (yych <= '7') goto yy1059; yy942: YYDEBUG(942, *YYCURSOR); -#line 1704 "ext/date/lib/parse_date.re" +#line 1715 "ext/date/lib/parse_date.re" { timelib_sll w, d; DEBUG_OUTPUT("isoweek"); @@ -19827,7 +19838,7 @@ yy942: TIMELIB_DEINIT; return TIMELIB_ISO_WEEK; } -#line 19831 "" +#line 19842 "" yy943: YYDEBUG(943, *YYCURSOR); yych = *++YYCURSOR; @@ -20303,7 +20314,7 @@ yy981: if (yych == 'e') goto yy1094; yy982: YYDEBUG(982, *YYCURSOR); -#line 1847 "ext/date/lib/parse_date.re" +#line 1858 "ext/date/lib/parse_date.re" { timelib_sll i; int behavior = 0; @@ -20319,7 +20330,7 @@ yy982: TIMELIB_DEINIT; return TIMELIB_RELATIVE; } -#line 20323 "" +#line 20334 "" yy983: YYDEBUG(983, *YYCURSOR); yych = *++YYCURSOR; @@ -20666,7 +20677,7 @@ yy1020: YYDEBUG(1020, *YYCURSOR); ++YYCURSOR; YYDEBUG(1021, *YYCURSOR); -#line 1553 "ext/date/lib/parse_date.re" +#line 1564 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("pointed date YYYY"); TIMELIB_INIT; @@ -20677,7 +20688,7 @@ yy1020: TIMELIB_DEINIT; return TIMELIB_DATE_FULL_POINTED; } -#line 20681 "" +#line 20692 "" yy1022: YYDEBUG(1022, *YYCURSOR); ++YYCURSOR; @@ -20706,7 +20717,7 @@ yy1024: } yy1025: YYDEBUG(1025, *YYCURSOR); -#line 1484 "ext/date/lib/parse_date.re" +#line 1495 "ext/date/lib/parse_date.re" { int length = 0; DEBUG_OUTPUT("iso8601date2"); @@ -20719,7 +20730,7 @@ yy1025: TIMELIB_DEINIT; return TIMELIB_ISO_DATE; } -#line 20723 "" +#line 20734 "" yy1026: YYDEBUG(1026, *YYCURSOR); yyaccept = 15; @@ -20939,7 +20950,7 @@ yy1042: } yy1043: YYDEBUG(1043, *YYCURSOR); -#line 1472 "ext/date/lib/parse_date.re" +#line 1483 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("iso8601date4 | iso8601date2 | iso8601dateslash | dateslash"); TIMELIB_INIT; @@ -20950,7 +20961,7 @@ yy1043: TIMELIB_DEINIT; return TIMELIB_ISO_DATE; } -#line 20954 "" +#line 20965 "" yy1044: YYDEBUG(1044, *YYCURSOR); yyaccept = 26; @@ -21065,7 +21076,7 @@ yy1047: } yy1048: YYDEBUG(1048, *YYCURSOR); -#line 1633 "ext/date/lib/parse_date.re" +#line 1644 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("datenocolon"); TIMELIB_INIT; @@ -21076,7 +21087,7 @@ yy1048: TIMELIB_DEINIT; return TIMELIB_DATE_NOCOLON; } -#line 21080 "" +#line 21091 "" yy1049: YYDEBUG(1049, *YYCURSOR); yych = *++YYCURSOR; @@ -21146,7 +21157,7 @@ yy1059: YYDEBUG(1059, *YYCURSOR); ++YYCURSOR; YYDEBUG(1060, *YYCURSOR); -#line 1685 "ext/date/lib/parse_date.re" +#line 1696 "ext/date/lib/parse_date.re" { timelib_sll w, d; DEBUG_OUTPUT("isoweekday"); @@ -21164,7 +21175,7 @@ yy1059: TIMELIB_DEINIT; return TIMELIB_ISO_WEEK; } -#line 21168 "" +#line 21179 "" yy1061: YYDEBUG(1061, *YYCURSOR); yych = *++YYCURSOR; @@ -21227,7 +21238,7 @@ yy1069: if (yych <= '9') goto yy1143; yy1070: YYDEBUG(1070, *YYCURSOR); -#line 1723 "ext/date/lib/parse_date.re" +#line 1734 "ext/date/lib/parse_date.re" { int length = 0; DEBUG_OUTPUT("pgtextshort"); @@ -21240,7 +21251,7 @@ yy1070: TIMELIB_DEINIT; return TIMELIB_PG_TEXT; } -#line 21244 "" +#line 21255 "" yy1071: YYDEBUG(1071, *YYCURSOR); yych = *++YYCURSOR; @@ -21713,7 +21724,7 @@ yy1106: ++YYCURSOR; yy1107: YYDEBUG(1107, *YYCURSOR); -#line 1184 "ext/date/lib/parse_date.re" +#line 1195 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("tomorrow"); TIMELIB_INIT; @@ -21724,7 +21735,7 @@ yy1107: TIMELIB_DEINIT; return TIMELIB_RELATIVE; } -#line 21728 "" +#line 21739 "" yy1108: YYDEBUG(1108, *YYCURSOR); yyaccept = 28; @@ -22061,7 +22072,7 @@ yy1140: YYDEBUG(1140, *YYCURSOR); ++YYCURSOR; YYDEBUG(1141, *YYCURSOR); -#line 1737 "ext/date/lib/parse_date.re" +#line 1748 "ext/date/lib/parse_date.re" { int length = 0; DEBUG_OUTPUT("pgtextreverse"); @@ -22074,7 +22085,7 @@ yy1140: TIMELIB_DEINIT; return TIMELIB_PG_TEXT; } -#line 22078 "" +#line 22089 "" yy1142: YYDEBUG(1142, *YYCURSOR); ++YYCURSOR; @@ -22118,7 +22129,7 @@ yy1144: } yy1145: YYDEBUG(1145, *YYCURSOR); -#line 1279 "ext/date/lib/parse_date.re" +#line 1290 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("backof | frontof"); TIMELIB_INIT; @@ -22140,7 +22151,7 @@ yy1145: TIMELIB_DEINIT; return TIMELIB_LF_DAY_OF_MONTH; } -#line 22144 "" +#line 22155 "" yy1146: YYDEBUG(1146, *YYCURSOR); yyaccept = 29; @@ -22464,7 +22475,7 @@ yy1171: } yy1172: YYDEBUG(1172, *YYCURSOR); -#line 1823 "ext/date/lib/parse_date.re" +#line 1834 "ext/date/lib/parse_date.re" { timelib_sll i; int behavior = 0; @@ -22487,7 +22498,7 @@ yy1172: TIMELIB_DEINIT; return TIMELIB_RELATIVE; } -#line 22491 "" +#line 22502 "" yy1173: YYDEBUG(1173, *YYCURSOR); yych = *++YYCURSOR; @@ -22499,7 +22510,7 @@ yy1174: ++YYCURSOR; yy1175: YYDEBUG(1175, *YYCURSOR); -#line 1141 "ext/date/lib/parse_date.re" +#line 1152 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("yesterday"); TIMELIB_INIT; @@ -22510,7 +22521,7 @@ yy1175: TIMELIB_DEINIT; return TIMELIB_RELATIVE; } -#line 22514 "" +#line 22525 "" yy1176: YYDEBUG(1176, *YYCURSOR); yyaccept = 31; @@ -23003,7 +23014,7 @@ yy1222: YYDEBUG(1222, *YYCURSOR); ++YYCURSOR; YYDEBUG(1223, *YYCURSOR); -#line 1889 "ext/date/lib/parse_date.re" +#line 1900 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("dateshortwithtimeshort12 | dateshortwithtimelong12"); TIMELIB_INIT; @@ -23026,7 +23037,7 @@ yy1222: TIMELIB_DEINIT; return TIMELIB_SHORTDATE_WITH_TIME; } -#line 23030 "" +#line 23041 "" yy1224: YYDEBUG(1224, *YYCURSOR); yych = *++YYCURSOR; @@ -23528,7 +23539,7 @@ yy1268: YYDEBUG(1268, *YYCURSOR); ++YYCURSOR; YYDEBUG(1269, *YYCURSOR); -#line 1302 "ext/date/lib/parse_date.re" +#line 1313 "ext/date/lib/parse_date.re" { timelib_sll i; int behavior = 0; @@ -23549,7 +23560,7 @@ yy1268: TIMELIB_DEINIT; return TIMELIB_WEEK_DAY_OF_MONTH; } -#line 23553 "" +#line 23564 "" yy1270: YYDEBUG(1270, *YYCURSOR); yyaccept = 24; @@ -23596,7 +23607,7 @@ yy1273: YYDEBUG(1273, *YYCURSOR); ++YYCURSOR; YYDEBUG(1274, *YYCURSOR); -#line 1262 "ext/date/lib/parse_date.re" +#line 1273 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("firstdayof | lastdayof"); TIMELIB_INIT; @@ -23612,12 +23623,12 @@ yy1273: TIMELIB_DEINIT; return TIMELIB_LF_DAY_OF_MONTH; } -#line 23616 "" +#line 23627 "" yy1275: YYDEBUG(1275, *YYCURSOR); ++YYCURSOR; YYDEBUG(1276, *YYCURSOR); -#line 1498 "ext/date/lib/parse_date.re" +#line 1509 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("iso8601datex"); TIMELIB_INIT; @@ -23628,7 +23639,7 @@ yy1275: TIMELIB_DEINIT; return TIMELIB_ISO_DATE; } -#line 23632 "" +#line 23643 "" yy1277: YYDEBUG(1277, *YYCURSOR); yych = *++YYCURSOR; @@ -23731,7 +23742,7 @@ yy1290: YYDEBUG(1290, *YYCURSOR); ++YYCURSOR; YYDEBUG(1291, *YYCURSOR); -#line 1342 "ext/date/lib/parse_date.re" +#line 1353 "ext/date/lib/parse_date.re" { DEBUG_OUTPUT("mssqltime"); TIMELIB_INIT; @@ -23750,7 +23761,7 @@ yy1290: TIMELIB_DEINIT; return TIMELIB_TIME24_WITH_ZONE; } -#line 23754 "" +#line 23765 "" yy1292: YYDEBUG(1292, *YYCURSOR); yych = *++YYCURSOR; @@ -24174,7 +24185,7 @@ yy1328: if (yych <= '9') goto yy1331; yy1329: YYDEBUG(1329, *YYCURSOR); -#line 1645 "ext/date/lib/parse_date.re" +#line 1656 "ext/date/lib/parse_date.re" { int tz_not_found; DEBUG_OUTPUT("xmlrpc | xmlrpcnocolon | soap | wddx | exif"); @@ -24199,7 +24210,7 @@ yy1329: TIMELIB_DEINIT; return TIMELIB_XMLRPC_SOAP; } -#line 24203 "" +#line 24214 "" yy1330: YYDEBUG(1330, *YYCURSOR); yych = *++YYCURSOR; @@ -24569,7 +24580,7 @@ yy1374: if (yych <= ':') goto yy1383; yy1375: YYDEBUG(1375, *YYCURSOR); -#line 1751 "ext/date/lib/parse_date.re" +#line 1762 "ext/date/lib/parse_date.re" { int tz_not_found; DEBUG_OUTPUT("clf"); @@ -24592,7 +24603,7 @@ yy1375: TIMELIB_DEINIT; return TIMELIB_CLF; } -#line 24596 "" +#line 24607 "" yy1376: YYDEBUG(1376, *YYCURSOR); yyaccept = 33; @@ -24824,7 +24835,7 @@ yy1406: if (yych == ':') goto yy1286; goto yy1329; } -#line 1979 "ext/date/lib/parse_date.re" +#line 1990 "ext/date/lib/parse_date.re" } diff --git a/ext/date/lib/parse_date.re b/ext/date/lib/parse_date.re index 3159ff7fa8c..5d259ed4e2c 100644 --- a/ext/date/lib/parse_date.re +++ b/ext/date/lib/parse_date.re @@ -711,6 +711,17 @@ static const timelib_relunit* timelib_lookup_relunit(const char **ptr) return value; } +static void add_with_overflow(Scanner *s, timelib_sll *e, timelib_sll amount, int multiplier) +{ +#if defined(__has_builtin) && __has_builtin(__builtin_saddll_overflow) + if (__builtin_saddll_overflow(*e, amount * multiplier, e)) { + add_error(s, TIMELIB_ERR_NUMBER_OUT_OF_RANGE, "Number out of range"); + } +#else + *e += (amount * multiplier); +#endif +} + /** * The time_part parameter is a flag. It can be TIMELIB_TIME_PART_KEEP in case * the time portion should not be reset to midnight, or @@ -726,13 +737,13 @@ static void timelib_set_relative(const char **ptr, timelib_sll amount, int behav } switch (relunit->unit) { - case TIMELIB_MICROSEC: s->time->relative.us += amount * relunit->multiplier; break; - case TIMELIB_SECOND: s->time->relative.s += amount * relunit->multiplier; break; - case TIMELIB_MINUTE: s->time->relative.i += amount * relunit->multiplier; break; - case TIMELIB_HOUR: s->time->relative.h += amount * relunit->multiplier; break; - case TIMELIB_DAY: s->time->relative.d += amount * relunit->multiplier; break; - case TIMELIB_MONTH: s->time->relative.m += amount * relunit->multiplier; break; - case TIMELIB_YEAR: s->time->relative.y += amount * relunit->multiplier; break; + case TIMELIB_MICROSEC: add_with_overflow(s, &s->time->relative.us, amount, relunit->multiplier); break; + case TIMELIB_SECOND: add_with_overflow(s, &s->time->relative.s, amount, relunit->multiplier); break; + case TIMELIB_MINUTE: add_with_overflow(s, &s->time->relative.i, amount, relunit->multiplier); break; + case TIMELIB_HOUR: add_with_overflow(s, &s->time->relative.h, amount, relunit->multiplier); break; + case TIMELIB_DAY: add_with_overflow(s, &s->time->relative.d, amount, relunit->multiplier); break; + case TIMELIB_MONTH: add_with_overflow(s, &s->time->relative.m, amount, relunit->multiplier); break; + case TIMELIB_YEAR: add_with_overflow(s, &s->time->relative.y, amount, relunit->multiplier); break; case TIMELIB_WEEKDAY: TIMELIB_HAVE_WEEKDAY_RELATIVE(); diff --git a/ext/date/lib/timelib.c b/ext/date/lib/timelib.c index d42c69bbd6f..6473a2798a8 100644 --- a/ext/date/lib/timelib.c +++ b/ext/date/lib/timelib.c @@ -187,14 +187,22 @@ timelib_long timelib_date_to_int(timelib_time *d, int *error) void timelib_decimal_hour_to_hms(double h, int *hour, int *min, int *sec) { - if (h > 0) { - *hour = floor(h); - *min = floor((h - *hour) * 60); - *sec = (h - *hour - ((float) *min / 60)) * 3600; - } else { - *hour = ceil(h); - *min = 0 - ceil((h - *hour) * 60); - *sec = 0 - (h - *hour - ((float) *min / -60)) * 3600; + bool swap = false; + int seconds; + + if (h < 0) { + swap = true; + h = fabs(h); + } + + *hour = floor(h); + seconds = floor((h - *hour) * 3600); + + *min = seconds / 60; + *sec = seconds % 60; + + if (swap) { + *hour = 0 - *hour; } } diff --git a/ext/date/lib/timelib.h b/ext/date/lib/timelib.h index a532bf60356..4582fcfd469 100644 --- a/ext/date/lib/timelib.h +++ b/ext/date/lib/timelib.h @@ -30,9 +30,9 @@ # include "timelib_config.h" #endif -#define TIMELIB_VERSION 202209 -#define TIMELIB_EXTENDED_VERSION 20220901 -#define TIMELIB_ASCII_VERSION "2022.09" +#define TIMELIB_VERSION 202210 +#define TIMELIB_EXTENDED_VERSION 20221001 +#define TIMELIB_ASCII_VERSION "2022.10" #include #include From 73246bac003a95efa8175f05fe219825f8540c83 Mon Sep 17 00:00:00 2001 From: Derick Rethans Date: Thu, 23 Nov 2023 16:18:34 +0000 Subject: [PATCH 2/2] Update NEWS --- NEWS | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/NEWS b/NEWS index d2ed14804a5..39670fa94f9 100644 --- a/NEWS +++ b/NEWS @@ -8,6 +8,10 @@ PHP NEWS . Fixed oss-fuzz #64209 (In-place modification of filename in php_message_handler_for_zend). (ilutov) +- Date: + . Fixed improbably integer overflow while parsing really large (or small) + Unix timestamps. (Derick) + - DOM: . Fixed bug GH-12616 (DOM: Removing XMLNS namespace node results in invalid default: prefix). (nielsdos)