From 8067e86c4edfd56c777e84f36c1c983666d21bbc Mon Sep 17 00:00:00 2001 From: sebres Date: Fri, 15 Mar 2024 18:20:40 +0100 Subject: [PATCH] better solution for tclDate.c (since Number is not an int) avoiding overflow-trap; cherry-pick from tcl-core --- generic/tclDate.c | 17 ++++------------- generic/tclGetDate.y | 17 ++++------------- 2 files changed, 8 insertions(+), 26 deletions(-) diff --git a/generic/tclDate.c b/generic/tclDate.c index 1e25884..35879d5 100644 --- a/generic/tclDate.c +++ b/generic/tclDate.c @@ -139,7 +139,7 @@ typedef struct _TABLE { const char *name; int type; - Tcl_WideInt value; + long long value; } TABLE; /* @@ -224,7 +224,7 @@ extern int TclDatedebug; union YYSTYPE { - Tcl_WideInt Number; + long long Number; enum _MERIDIAN Meridian; @@ -2676,11 +2676,6 @@ LookupWord( return tID; } -/* int overflows may happens here (expected case) */ -#if defined(__GNUC__) || defined(__GNUG__) -# pragma GCC optimize("no-trapv") -#endif - static int TclDatelex( YYSTYPE* yylvalPtr, @@ -2711,7 +2706,7 @@ TclDatelex( /* * Convert the string into a number; count the number of digits. */ - int num = c - '0'; + long long num = c - '0'; p = (char *)yyInput; while (isdigit(UCHAR(c = *(++p)))) { if (num >= 0) { @@ -2743,7 +2738,7 @@ TclDatelex( location->last_column = yyInput - info->dateStart - 1; return tISOBASL; } - if (num < 0) { /* overflow */ + if (yyDigitCount > 14) { /* overflow */ return tID; } if (yyDigitCount == 8) { @@ -2818,10 +2813,6 @@ TclDatelex( } while (Count > 0); } } - -#if defined(__GNUC__) || defined(__GNUG__) -# pragma GCC reset_options -#endif int TclClockFreeScan( diff --git a/generic/tclGetDate.y b/generic/tclGetDate.y index 1b5c481..3fa0aa1 100644 --- a/generic/tclGetDate.y +++ b/generic/tclGetDate.y @@ -89,7 +89,7 @@ typedef struct _TABLE { const char *name; int type; - Tcl_WideInt value; + long long value; } TABLE; /* @@ -103,7 +103,7 @@ typedef enum _DSTMODE { %} %union { - Tcl_WideInt Number; + long long Number; enum _MERIDIAN Meridian; } @@ -877,11 +877,6 @@ LookupWord( return tID; } -/* int overflows may happens here (expected case) */ -#if defined(__GNUC__) || defined(__GNUG__) -# pragma GCC optimize("no-trapv") -#endif - static int TclDatelex( YYSTYPE* yylvalPtr, @@ -912,7 +907,7 @@ TclDatelex( /* * Convert the string into a number; count the number of digits. */ - int num = c - '0'; + long long num = c - '0'; p = (char *)yyInput; while (isdigit(UCHAR(c = *(++p)))) { if (num >= 0) { @@ -944,7 +939,7 @@ TclDatelex( location->last_column = yyInput - info->dateStart - 1; return tISOBASL; } - if (num < 0) { /* overflow */ + if (yyDigitCount > 14) { /* overflow */ return tID; } if (yyDigitCount == 8) { @@ -1019,10 +1014,6 @@ TclDatelex( } while (Count > 0); } } - -#if defined(__GNUC__) || defined(__GNUG__) -# pragma GCC reset_options -#endif int TclClockFreeScan(