From 710f5eadee88f492e35dd4c9288ee3ee217bfe27 Mon Sep 17 00:00:00 2001 From: sebres Date: Fri, 15 Nov 2024 17:40:10 +0000 Subject: [PATCH 1/2] revert (too many non-functional space changes by backporting, will be repeated with fixed spaces) --- generic/tclDate.c | 396 ++++++++++++++++++++++--------------------- generic/tclGetDate.y | 18 +- tests/clock.test | 49 +++--- 3 files changed, 244 insertions(+), 219 deletions(-) diff --git a/generic/tclDate.c b/generic/tclDate.c index 89228e7635d..7e2aded265b 100644 --- a/generic/tclDate.c +++ b/generic/tclDate.c @@ -472,7 +472,7 @@ typedef short yytype_int16; # endif # if (defined __cplusplus && ! defined EXIT_SUCCESS \ && ! ((defined YYMALLOC || defined malloc) \ - && (defined YYFREE || defined free))) + && (defined YYFREE || defined free))) # include /* INFRINGES ON USER NAME SPACE */ # ifndef EXIT_SUCCESS # define EXIT_SUCCESS 0 @@ -496,8 +496,8 @@ void free (void *); /* INFRINGES ON USER NAME SPACE */ #if (! defined yyoverflow \ && (! defined __cplusplus \ - || (defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL \ - && defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) + || (defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL \ + && defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) /* A type that is properly aligned for any stack member. */ union yyalloc @@ -526,11 +526,11 @@ union yyalloc # define YYSTACK_RELOCATE(Stack_alloc, Stack) \ do \ { \ - YYSIZE_T yynewbytes; \ - YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \ - Stack = &yyptr->Stack_alloc; \ - yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \ - yyptr += yynewbytes / sizeof (*yyptr); \ + YYSIZE_T yynewbytes; \ + YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \ + Stack = &yyptr->Stack_alloc; \ + yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \ + yyptr += yynewbytes / sizeof (*yyptr); \ } \ while (0) @@ -546,11 +546,11 @@ union yyalloc # else # define YYCOPY(Dst, Src, Count) \ do \ - { \ - YYSIZE_T yyi; \ - for (yyi = 0; yyi < (Count); yyi++) \ - (Dst)[yyi] = (Src)[yyi]; \ - } \ + { \ + YYSIZE_T yyi; \ + for (yyi = 0; yyi < (Count); yyi++) \ + (Dst)[yyi] = (Src)[yyi]; \ + } \ while (0) # endif # endif @@ -815,19 +815,19 @@ while (0) # define YYLLOC_DEFAULT(Current, Rhs, N) \ do \ if (N) \ - { \ - (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \ - (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \ - (Current).last_line = YYRHSLOC (Rhs, N).last_line; \ - (Current).last_column = YYRHSLOC (Rhs, N).last_column; \ - } \ + { \ + (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \ + (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \ + (Current).last_line = YYRHSLOC (Rhs, N).last_line; \ + (Current).last_column = YYRHSLOC (Rhs, N).last_column; \ + } \ else \ - { \ - (Current).first_line = (Current).last_line = \ - YYRHSLOC (Rhs, 0).last_line; \ - (Current).first_column = (Current).last_column = \ - YYRHSLOC (Rhs, 0).last_column; \ - } \ + { \ + (Current).first_line = (Current).last_line = \ + YYRHSLOC (Rhs, 0).last_line; \ + (Current).first_column = (Current).last_column = \ + YYRHSLOC (Rhs, 0).last_column; \ + } \ while (0) #endif @@ -868,18 +868,18 @@ yy_location_print_ (FILE *yyo, YYLTYPE const * const yylocp) { res += YYFPRINTF (yyo, "%d", yylocp->first_line); if (0 <= yylocp->first_column) - res += YYFPRINTF (yyo, ".%d", yylocp->first_column); + res += YYFPRINTF (yyo, ".%d", yylocp->first_column); } if (0 <= yylocp->last_line) { if (yylocp->first_line < yylocp->last_line) - { - res += YYFPRINTF (yyo, "-%d", yylocp->last_line); - if (0 <= end_col) - res += YYFPRINTF (yyo, ".%d", end_col); - } + { + res += YYFPRINTF (yyo, "-%d", yylocp->last_line); + if (0 <= end_col) + res += YYFPRINTF (yyo, ".%d", end_col); + } else if (0 <= end_col && yylocp->first_column < end_col) - res += YYFPRINTF (yyo, "-%d", end_col); + res += YYFPRINTF (yyo, "-%d", end_col); } return res; } @@ -899,7 +899,7 @@ do { \ { \ YYFPRINTF (stderr, "%s ", Title); \ yy_symbol_print (stderr, \ - Type, Value, Location, info); \ + Type, Value, Location, info); \ YYFPRINTF (stderr, "\n"); \ } \ } while (0) @@ -934,7 +934,7 @@ static void yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep, YYLTYPE const * const yylocationp, DateInfo* info) { YYFPRINTF (yyoutput, "%s %s (", - yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]); + yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]); YY_LOCATION_PRINT (yyoutput, *yylocationp); YYFPRINTF (yyoutput, ": "); @@ -977,15 +977,15 @@ yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, YYLTYPE *yylsp, int yyrule int yynrhs = yyr2[yyrule]; int yyi; YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n", - yyrule - 1, yylno); + yyrule - 1, yylno); /* The symbols being reduced. */ for (yyi = 0; yyi < yynrhs; yyi++) { YYFPRINTF (stderr, " $%d = ", yyi + 1); yy_symbol_print (stderr, - yystos[yyssp[yyi + 1 - yynrhs]], - &(yyvsp[(yyi + 1) - (yynrhs)]) - , &(yylsp[(yyi + 1) - (yynrhs)]) , info); + yystos[yyssp[yyi + 1 - yynrhs]], + &(yyvsp[(yyi + 1) - (yynrhs)]) + , &(yylsp[(yyi + 1) - (yynrhs)]) , info); YYFPRINTF (stderr, "\n"); } } @@ -1079,27 +1079,27 @@ yytnamerr (char *yyres, const char *yystr) char const *yyp = yystr; for (;;) - switch (*++yyp) - { - case '\'': - case ',': - goto do_not_strip_quotes; - - case '\\': - if (*++yyp != '\\') - goto do_not_strip_quotes; - /* Fall through. */ - default: - if (yyres) - yyres[yyn] = *yyp; - yyn++; - break; - - case '"': - if (yyres) - yyres[yyn] = '\0'; - return yyn; - } + switch (*++yyp) + { + case '\'': + case ',': + goto do_not_strip_quotes; + + case '\\': + if (*++yyp != '\\') + goto do_not_strip_quotes; + /* Fall through. */ + default: + if (yyres) + yyres[yyn] = *yyp; + yyn++; + break; + + case '"': + if (yyres) + yyres[yyn] = '\0'; + return yyn; + } do_not_strip_quotes: ; } @@ -1120,7 +1120,7 @@ yytnamerr (char *yyres, const char *yystr) required number of bytes is too large to store. */ static int yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, - yytype_int16 *yyssp, int yytoken) + yytype_int16 *yyssp, int yytoken) { YYSIZE_T yysize0 = yytnamerr (YY_NULLPTR, yytname[yytoken]); YYSIZE_T yysize = yysize0; @@ -1161,43 +1161,43 @@ yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, int yyn = yypact[*yyssp]; yyarg[yycount++] = yytname[yytoken]; if (!yypact_value_is_default (yyn)) - { - /* Start YYX at -YYN if negative to avoid negative indexes in - YYCHECK. In other words, skip the first -YYN actions for - this state because they are default actions. */ - int yyxbegin = yyn < 0 ? -yyn : 0; - /* Stay within bounds of both yycheck and yytname. */ - int yychecklim = YYLAST - yyn + 1; - int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; - int yyx; - - for (yyx = yyxbegin; yyx < yyxend; ++yyx) - if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR - && !yytable_value_is_error (yytable[yyx + yyn])) - { - if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) - { - yycount = 1; - yysize = yysize0; - break; - } - yyarg[yycount++] = yytname[yyx]; - { - YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULLPTR, yytname[yyx]); - if (! (yysize <= yysize1 - && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) - return 2; - yysize = yysize1; - } - } - } + { + /* Start YYX at -YYN if negative to avoid negative indexes in + YYCHECK. In other words, skip the first -YYN actions for + this state because they are default actions. */ + int yyxbegin = yyn < 0 ? -yyn : 0; + /* Stay within bounds of both yycheck and yytname. */ + int yychecklim = YYLAST - yyn + 1; + int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; + int yyx; + + for (yyx = yyxbegin; yyx < yyxend; ++yyx) + if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR + && !yytable_value_is_error (yytable[yyx + yyn])) + { + if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) + { + yycount = 1; + yysize = yysize0; + break; + } + yyarg[yycount++] = yytname[yyx]; + { + YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULLPTR, yytname[yyx]); + if (! (yysize <= yysize1 + && yysize1 <= YYSTACK_ALLOC_MAXIMUM)) + return 2; + yysize = yysize1; + } + } + } } switch (yycount) { # define YYCASE_(N, S) \ case N: \ - yyformat = S; \ + yyformat = S; \ break default: /* Avoid compiler warnings. */ YYCASE_(0, YY_("syntax error")); @@ -1220,8 +1220,8 @@ yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, { *yymsg_alloc = 2 * yysize; if (! (yysize <= *yymsg_alloc - && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM)) - *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM; + && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM)) + *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM; return 1; } @@ -1233,15 +1233,15 @@ yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg, int yyi = 0; while ((*yyp = *yyformat) != '\0') if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount) - { - yyp += yytnamerr (yyp, yyarg[yyi++]); - yyformat += 2; - } + { + yyp += yytnamerr (yyp, yyarg[yyi++]); + yyformat += 2; + } else - { - yyp++; - yyformat++; - } + { + yyp++; + yyformat++; + } } return 0; } @@ -1379,26 +1379,26 @@ YYLTYPE yylloc = yyloc_default; #ifdef yyoverflow { - /* Give user a chance to reallocate the stack. Use copies of - these so that the &'s don't force the real ones into - memory. */ - YYSTYPE *yyvs1 = yyvs; - yytype_int16 *yyss1 = yyss; - YYLTYPE *yyls1 = yyls; - - /* Each stack pointer address is followed by the size of the - data in use in that stack, in bytes. This used to be a - conditional around just the two extra args, but that might - be undefined if yyoverflow is a macro. */ - yyoverflow (YY_("memory exhausted"), - &yyss1, yysize * sizeof (*yyssp), - &yyvs1, yysize * sizeof (*yyvsp), - &yyls1, yysize * sizeof (*yylsp), - &yystacksize); - - yyls = yyls1; - yyss = yyss1; - yyvs = yyvs1; + /* Give user a chance to reallocate the stack. Use copies of + these so that the &'s don't force the real ones into + memory. */ + YYSTYPE *yyvs1 = yyvs; + yytype_int16 *yyss1 = yyss; + YYLTYPE *yyls1 = yyls; + + /* Each stack pointer address is followed by the size of the + data in use in that stack, in bytes. This used to be a + conditional around just the two extra args, but that might + be undefined if yyoverflow is a macro. */ + yyoverflow (YY_("memory exhausted"), + &yyss1, yysize * sizeof (*yyssp), + &yyvs1, yysize * sizeof (*yyvsp), + &yyls1, yysize * sizeof (*yylsp), + &yystacksize); + + yyls = yyls1; + yyss = yyss1; + yyvs = yyvs1; } #else /* no yyoverflow */ # ifndef YYSTACK_RELOCATE @@ -1406,23 +1406,23 @@ YYLTYPE yylloc = yyloc_default; # else /* Extend the stack our own way. */ if (YYMAXDEPTH <= yystacksize) - goto yyexhaustedlab; + goto yyexhaustedlab; yystacksize *= 2; if (YYMAXDEPTH < yystacksize) - yystacksize = YYMAXDEPTH; + yystacksize = YYMAXDEPTH; { - yytype_int16 *yyss1 = yyss; - union yyalloc *yyptr = - (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); - if (! yyptr) - goto yyexhaustedlab; - YYSTACK_RELOCATE (yyss_alloc, yyss); - YYSTACK_RELOCATE (yyvs_alloc, yyvs); - YYSTACK_RELOCATE (yyls_alloc, yyls); + yytype_int16 *yyss1 = yyss; + union yyalloc *yyptr = + (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); + if (! yyptr) + goto yyexhaustedlab; + YYSTACK_RELOCATE (yyss_alloc, yyss); + YYSTACK_RELOCATE (yyvs_alloc, yyvs); + YYSTACK_RELOCATE (yyls_alloc, yyls); # undef YYSTACK_RELOCATE - if (yyss1 != yyssa) - YYSTACK_FREE (yyss1); + if (yyss1 != yyssa) + YYSTACK_FREE (yyss1); } # endif #endif /* no yyoverflow */ @@ -1432,10 +1432,10 @@ YYLTYPE yylloc = yyloc_default; yylsp = yyls + yysize - 1; YYDPRINTF ((stderr, "Stack size increased to %lu\n", - (unsigned long) yystacksize)); + (unsigned long) yystacksize)); if (yyss + yystacksize - 1 <= yyssp) - YYABORT; + YYABORT; } YYDPRINTF ((stderr, "Entering state %d\n", yystate)); @@ -1487,7 +1487,7 @@ YYLTYPE yylloc = yyloc_default; if (yyn <= 0) { if (yytable_value_is_error (yyn)) - goto yyerrlab; + goto yyerrlab; yyn = -yyn; goto yyreduce; } @@ -1544,7 +1544,7 @@ YYLTYPE yylloc = yyloc_default; YY_REDUCE_PRINT (yyn); switch (yyn) { - case 4: + case 4: { yyHaveTime++; @@ -2098,33 +2098,33 @@ YYLTYPE yylloc = yyloc_default; yyerror (&yylloc, info, YY_("syntax error")); #else # define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \ - yyssp, yytoken) + yyssp, yytoken) { - char const *yymsgp = YY_("syntax error"); - int yysyntax_error_status; - yysyntax_error_status = YYSYNTAX_ERROR; - if (yysyntax_error_status == 0) - yymsgp = yymsg; - else if (yysyntax_error_status == 1) - { - if (yymsg != yymsgbuf) - YYSTACK_FREE (yymsg); - yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc); - if (!yymsg) - { - yymsg = yymsgbuf; - yymsg_alloc = sizeof yymsgbuf; - yysyntax_error_status = 2; - } - else - { - yysyntax_error_status = YYSYNTAX_ERROR; - yymsgp = yymsg; - } - } - yyerror (&yylloc, info, yymsgp); - if (yysyntax_error_status == 2) - goto yyexhaustedlab; + char const *yymsgp = YY_("syntax error"); + int yysyntax_error_status; + yysyntax_error_status = YYSYNTAX_ERROR; + if (yysyntax_error_status == 0) + yymsgp = yymsg; + else if (yysyntax_error_status == 1) + { + if (yymsg != yymsgbuf) + YYSTACK_FREE (yymsg); + yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc); + if (!yymsg) + { + yymsg = yymsgbuf; + yymsg_alloc = sizeof yymsgbuf; + yysyntax_error_status = 2; + } + else + { + yysyntax_error_status = YYSYNTAX_ERROR; + yymsgp = yymsg; + } + } + yyerror (&yylloc, info, yymsgp); + if (yysyntax_error_status == 2) + goto yyexhaustedlab; } # undef YYSYNTAX_ERROR #endif @@ -2135,20 +2135,20 @@ YYLTYPE yylloc = yyloc_default; if (yyerrstatus == 3) { /* If just tried and failed to reuse lookahead token after an - error, discard it. */ + error, discard it. */ if (yychar <= YYEOF) - { - /* Return failure if at end of input. */ - if (yychar == YYEOF) - YYABORT; - } + { + /* Return failure if at end of input. */ + if (yychar == YYEOF) + YYABORT; + } else - { - yydestruct ("Error: discarding", - yytoken, &yylval, &yylloc, info); - yychar = YYEMPTY; - } + { + yydestruct ("Error: discarding", + yytoken, &yylval, &yylloc, info); + yychar = YYEMPTY; + } } /* Else will try to reuse lookahead token after shifting the error @@ -2186,23 +2186,23 @@ YYLTYPE yylloc = yyloc_default; { yyn = yypact[yystate]; if (!yypact_value_is_default (yyn)) - { - yyn += YYTERROR; - if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) - { - yyn = yytable[yyn]; - if (0 < yyn) - break; - } - } + { + yyn += YYTERROR; + if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) + { + yyn = yytable[yyn]; + if (0 < yyn) + break; + } + } /* Pop the current state because it cannot handle the error token. */ if (yyssp == yyss) - YYABORT; + YYABORT; yyerror_range[1] = *yylsp; yydestruct ("Error: popping", - yystos[yystate], yyvsp, yylsp, info); + yystos[yystate], yyvsp, yylsp, info); YYPOPSTACK (1); yystate = *yyssp; YY_STACK_PRINT (yyss, yyssp); @@ -2253,10 +2253,10 @@ YYLTYPE yylloc = yyloc_default; if (yychar != YYEMPTY) { /* Make sure we have latest lookahead translation. See comments at - user semantic actions for why this is necessary. */ + user semantic actions for why this is necessary. */ yytoken = YYTRANSLATE (yychar); yydestruct ("Cleanup: discarding lookahead", - yytoken, &yylval, &yylloc, info); + yytoken, &yylval, &yylloc, info); } /* Do not reclaim the symbols of the rule whose action triggered this YYABORT or YYACCEPT. */ @@ -2265,7 +2265,7 @@ YYLTYPE yylloc = yyloc_default; while (yyssp != yyss) { yydestruct ("Cleanup: popping", - yystos[*yyssp], yyvsp, yylsp, info); + yystos[*yyssp], yyvsp, yylsp, info); YYPOPSTACK (1); } #ifndef yyoverflow @@ -2517,15 +2517,27 @@ ToSeconds( time_t Seconds, MERIDIAN Meridian) { + if (Minutes < 0 || Minutes > 59 || Seconds < 0 || Seconds > 59) { + return -1; + } switch (Meridian) { case MER24: - return (Hours * 60 + Minutes) * 60 + Seconds; + if (Hours < 0 || Hours > 23) { + return -1; + } + return (Hours * 60L + Minutes) * 60L + Seconds; case MERam: - return ((Hours % 12) * 60 + Minutes) * 60 + Seconds; + if (Hours < 1 || Hours > 12) { + return -1; + } + return ((Hours % 12) * 60L + Minutes) * 60L + Seconds; case MERpm: - return (((Hours % 12) + 12) * 60 + Minutes) * 60 + Seconds; + if (Hours < 1 || Hours > 12) { + return -1; + } + return (((Hours % 12) + 12) * 60L + Minutes) * 60L + Seconds; } - return -1; /* Should never be reached */ + return -1; /* Should never be reached */ } static int diff --git a/generic/tclGetDate.y b/generic/tclGetDate.y index daadb0b93d5..3a55b8e3cd7 100644 --- a/generic/tclGetDate.y +++ b/generic/tclGetDate.y @@ -738,13 +738,25 @@ ToSeconds( time_t Seconds, MERIDIAN Meridian) { + if (Minutes < 0 || Minutes > 59 || Seconds < 0 || Seconds > 59) { + return -1; + } switch (Meridian) { case MER24: - return (Hours * 60 + Minutes) * 60 + Seconds; + if (Hours < 0 || Hours > 23) { + return -1; + } + return (Hours * 60L + Minutes) * 60L + Seconds; case MERam: - return ((Hours % 12) * 60 + Minutes) * 60 + Seconds; + if (Hours < 1 || Hours > 12) { + return -1; + } + return ((Hours % 12) * 60L + Minutes) * 60L + Seconds; case MERpm: - return (((Hours % 12) + 12) * 60 + Minutes) * 60 + Seconds; + if (Hours < 1 || Hours > 12) { + return -1; + } + return (((Hours % 12) + 12) * 60L + Minutes) * 60L + Seconds; } return -1; /* Should never be reached */ } diff --git a/tests/clock.test b/tests/clock.test index d302a6704d9..92f66b8f4e6 100644 --- a/tests/clock.test +++ b/tests/clock.test @@ -36136,7 +36136,7 @@ test clock-46.6 {freescan: regression test - bad time} \ # 13:00 am/pm are invalid input strings... list [clock scan "13:00 am" -base 0 -gmt 1] \ [clock scan "13:00 pm" -base 0 -gmt 1] - } -result {3600 46800} + } -result {-1 -1} test clock-46.7 {regression test - switch day by large not-valid time, see bug [3ee8f1c2a785f4d8]} { list [clock scan 23:59:59 -base 0 -gmt 1 -format %H:%M:%S] \ @@ -37119,29 +37119,30 @@ test clock-67.5 {Change scan %x output on global locale change [Bug 4a0c163d24]} msgcat::mclocale $current } -result {1} -test clock-68.1 {Leap second, minute, hour [f2b5f89c0d], regression test (no validity check)} -body { - set res {} - foreach {d i} { - "2012-06-30 23:59:60" 1341100800 - "2012-06-30 23:60:00" 1341100800 - "2012-06-30 24:00:00" 1341100800 - "2012-06-29 23:59:60" 1341014400 - "2012-05-30 23:59:60" 1338422400 - "2012-05-30 23:60:60" 1338422460 - "2012-05-30 24:00:60" 1338422460 - "2012-05-30 24:60:00" 1338426000 - } { - # check with free scan: - if {[set t [clock scan $d -gmt 1]] != $i} { - lappend res "free-scan \"$d\" == $t, expected $i" - } - # check with formatted scan: - if {[set t [clock scan $d -gmt 1 -format "%Y-%m-%d %H:%M:%S"]] != $i} { - lappend res "fmt-scan \"$d\" == $t, expected $i" - } - } - set res; # must be empty -} -result {} +test clock-68.1 {Leap second [f2b5f89c0d], valid} -constraints knownBug -body { + clock scan "2012-06-30 23:59:60" -gmt 1 +} -result 1341100800 +test clock-68.2 {Leap minute [f2b5f89c0d], valid} -constraints knownBug -body { + clock scan "2012-06-30 23:60:00" -gmt 1 +} -result 1341100800 +test clock-68.3 {Leap hour [f2b5f89c0d], valid} -constraints knownBug -body { + clock scan "2012-06-30 24:00:00" -gmt 1 +} -result 1341100800 +test clock-68.4 {Leap second [f2b5f89c0d], wrong day} -constraints knownBug -body { + clock scan "2012-06-29 23:59:60" -gmt 1 +} -result 1341014400 +test clock-68.5 {Leap second [f2b5f89c0d], wrong month} -constraints knownBug -body { + clock scan "2012-05-30 23:59:60" -gmt 1 +} -result 1338422400 +test clock-68.6 {Leap second [f2b5f89c0d], minute} -constraints knownBug -body { + clock scan "2012-05-30 23:60:60" -gmt 1 +} -result 1338422460 +test clock-68.7 {Leap second [f2b5f89c0d], hour + second} -constraints knownBug -body { + clock scan "2012-05-30 24:00:60" -gmt 1 +} -result 1338422460 +test clock-68.8 {Leap second [f2b5f89c0d], hour + minute} -constraints knownBug -body { + clock scan "2012-05-30 24:60:00" -gmt 1 +} -result 1338426000 # cleanup From ac07bf22a2e97722c09c50a9ddf56572118ddec3 Mon Sep 17 00:00:00 2001 From: sebres Date: Fri, 15 Nov 2024 17:44:02 +0000 Subject: [PATCH 2/2] fixed wrong time conversion by free-scan (-1 from ToSecond() caused day decrement) - now the result is the same as for formatted scan, backported from tclclockmod (8.7+); the fix is not really related to [f2b5f89c0d], but since 8.6 doesn't have validity rules, let it make consistent accross all versions. repeat fix [83c5c578cb124286] (without space changes) --- generic/tclDate.c | 20 ++++-------------- generic/tclGetDate.y | 20 ++++-------------- tests/clock.test | 49 ++++++++++++++++++++++---------------------- 3 files changed, 32 insertions(+), 57 deletions(-) diff --git a/generic/tclDate.c b/generic/tclDate.c index 7e2aded265b..648f139b30c 100644 --- a/generic/tclDate.c +++ b/generic/tclDate.c @@ -2517,27 +2517,15 @@ ToSeconds( time_t Seconds, MERIDIAN Meridian) { - if (Minutes < 0 || Minutes > 59 || Seconds < 0 || Seconds > 59) { - return -1; - } switch (Meridian) { case MER24: - if (Hours < 0 || Hours > 23) { - return -1; - } - return (Hours * 60L + Minutes) * 60L + Seconds; + return (Hours * 60 + Minutes) * 60 + Seconds; case MERam: - if (Hours < 1 || Hours > 12) { - return -1; - } - return ((Hours % 12) * 60L + Minutes) * 60L + Seconds; + return ((Hours % 12) * 60 + Minutes) * 60 + Seconds; case MERpm: - if (Hours < 1 || Hours > 12) { - return -1; - } - return (((Hours % 12) + 12) * 60L + Minutes) * 60L + Seconds; + return (((Hours % 12) + 12) * 60 + Minutes) * 60 + Seconds; } - return -1; /* Should never be reached */ + return -1; /* Should never be reached */ } static int diff --git a/generic/tclGetDate.y b/generic/tclGetDate.y index 3a55b8e3cd7..017b3d12878 100644 --- a/generic/tclGetDate.y +++ b/generic/tclGetDate.y @@ -738,27 +738,15 @@ ToSeconds( time_t Seconds, MERIDIAN Meridian) { - if (Minutes < 0 || Minutes > 59 || Seconds < 0 || Seconds > 59) { - return -1; - } switch (Meridian) { case MER24: - if (Hours < 0 || Hours > 23) { - return -1; - } - return (Hours * 60L + Minutes) * 60L + Seconds; + return (Hours * 60 + Minutes) * 60 + Seconds; case MERam: - if (Hours < 1 || Hours > 12) { - return -1; - } - return ((Hours % 12) * 60L + Minutes) * 60L + Seconds; + return ((Hours % 12) * 60 + Minutes) * 60 + Seconds; case MERpm: - if (Hours < 1 || Hours > 12) { - return -1; - } - return (((Hours % 12) + 12) * 60L + Minutes) * 60L + Seconds; + return (((Hours % 12) + 12) * 60 + Minutes) * 60 + Seconds; } - return -1; /* Should never be reached */ + return -1; /* Should never be reached */ } static int diff --git a/tests/clock.test b/tests/clock.test index 92f66b8f4e6..d302a6704d9 100644 --- a/tests/clock.test +++ b/tests/clock.test @@ -36136,7 +36136,7 @@ test clock-46.6 {freescan: regression test - bad time} \ # 13:00 am/pm are invalid input strings... list [clock scan "13:00 am" -base 0 -gmt 1] \ [clock scan "13:00 pm" -base 0 -gmt 1] - } -result {-1 -1} + } -result {3600 46800} test clock-46.7 {regression test - switch day by large not-valid time, see bug [3ee8f1c2a785f4d8]} { list [clock scan 23:59:59 -base 0 -gmt 1 -format %H:%M:%S] \ @@ -37119,30 +37119,29 @@ test clock-67.5 {Change scan %x output on global locale change [Bug 4a0c163d24]} msgcat::mclocale $current } -result {1} -test clock-68.1 {Leap second [f2b5f89c0d], valid} -constraints knownBug -body { - clock scan "2012-06-30 23:59:60" -gmt 1 -} -result 1341100800 -test clock-68.2 {Leap minute [f2b5f89c0d], valid} -constraints knownBug -body { - clock scan "2012-06-30 23:60:00" -gmt 1 -} -result 1341100800 -test clock-68.3 {Leap hour [f2b5f89c0d], valid} -constraints knownBug -body { - clock scan "2012-06-30 24:00:00" -gmt 1 -} -result 1341100800 -test clock-68.4 {Leap second [f2b5f89c0d], wrong day} -constraints knownBug -body { - clock scan "2012-06-29 23:59:60" -gmt 1 -} -result 1341014400 -test clock-68.5 {Leap second [f2b5f89c0d], wrong month} -constraints knownBug -body { - clock scan "2012-05-30 23:59:60" -gmt 1 -} -result 1338422400 -test clock-68.6 {Leap second [f2b5f89c0d], minute} -constraints knownBug -body { - clock scan "2012-05-30 23:60:60" -gmt 1 -} -result 1338422460 -test clock-68.7 {Leap second [f2b5f89c0d], hour + second} -constraints knownBug -body { - clock scan "2012-05-30 24:00:60" -gmt 1 -} -result 1338422460 -test clock-68.8 {Leap second [f2b5f89c0d], hour + minute} -constraints knownBug -body { - clock scan "2012-05-30 24:60:00" -gmt 1 -} -result 1338426000 +test clock-68.1 {Leap second, minute, hour [f2b5f89c0d], regression test (no validity check)} -body { + set res {} + foreach {d i} { + "2012-06-30 23:59:60" 1341100800 + "2012-06-30 23:60:00" 1341100800 + "2012-06-30 24:00:00" 1341100800 + "2012-06-29 23:59:60" 1341014400 + "2012-05-30 23:59:60" 1338422400 + "2012-05-30 23:60:60" 1338422460 + "2012-05-30 24:00:60" 1338422460 + "2012-05-30 24:60:00" 1338426000 + } { + # check with free scan: + if {[set t [clock scan $d -gmt 1]] != $i} { + lappend res "free-scan \"$d\" == $t, expected $i" + } + # check with formatted scan: + if {[set t [clock scan $d -gmt 1 -format "%Y-%m-%d %H:%M:%S"]] != $i} { + lappend res "fmt-scan \"$d\" == $t, expected $i" + } + } + set res; # must be empty +} -result {} # cleanup