From 8ac73bbb406135935ecd132107be21351f74d5d0 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Fri, 5 Apr 2024 21:25:20 +0000 Subject: Fix [df85199878]: Tcl_SetResult compiler warnings --- generic/tclDecls.h | 8 -------- 1 file changed, 8 deletions(-) diff --git a/generic/tclDecls.h b/generic/tclDecls.h index a91f718..8a226a9 100644 --- a/generic/tclDecls.h +++ b/generic/tclDecls.h @@ -3973,14 +3973,6 @@ extern const TclStubs *tclStubsPtr; (tclStubsPtr->tcl_SetVar(interp, varName, newValue, flags)) # define Tcl_ObjSetVar2(interp, part1, part2, newValue, flags) \ (tclStubsPtr->tcl_ObjSetVar2(interp, part1, part2, newValue, flags)) -#ifndef __cplusplus -# undef Tcl_EventuallyFree -# define Tcl_EventuallyFree \ - ((void (*)(void *,void *))(void *)(tclStubsPtr->tcl_EventuallyFree)) /* 132 */ -# undef Tcl_SetResult -# define Tcl_SetResult \ - ((void (*)(Tcl_Interp *, char *, void *))(void *)(tclStubsPtr->tcl_SetResult)) /* 232 */ -#endif #endif #if defined(_WIN32) && defined(UNICODE) -- cgit v0.12 From f0fa42f7094385b7cff6153d115cce5e5fd9bfa8 Mon Sep 17 00:00:00 2001 From: sebres Date: Sat, 6 Apr 2024 13:20:29 +0000 Subject: simple attempt to silence valgrind [167e0635db], improved error message by bad seconds (or -base), repair errorCode (index for badOption), remove unneeded code --- generic/tclClock.c | 22 ++++++++++++---------- tests/clock.test | 8 ++++++-- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/generic/tclClock.c b/generic/tclClock.c index 03a4a48..9aa8242 100644 --- a/generic/tclClock.c +++ b/generic/tclClock.c @@ -3322,7 +3322,7 @@ ClockParseFmtScnArgs( }; int optionIndex; /* Index of an option. */ int saw = 0; /* Flag == 1 if option was seen already. */ - int i; + int i, baseIdx; Tcl_WideInt baseVal; /* Base time, expressed in seconds from the Epoch */ if ( flags & (CLC_SCN_ARGS) ) { @@ -3330,7 +3330,7 @@ ClockParseFmtScnArgs( opts->flags |= dataPtr->defFlags & (CLF_VALIDATE); } else { /* clock value (as current base) */ - opts->baseObj = objv[1]; + opts->baseObj = objv[(baseIdx = 1)]; saw |= (1 << CLC_ARGS_BASE); } @@ -3382,7 +3382,7 @@ ClockParseFmtScnArgs( opts->timezoneObj = objv[i+1]; break; case CLC_ARGS_BASE: - opts->baseObj = objv[i+1]; + opts->baseObj = objv[(baseIdx = i+1)]; break; case CLC_ARGS_VALIDATE: if ( !(flags & CLC_SCN_ARGS) ) { @@ -3441,7 +3441,7 @@ ClockParseFmtScnArgs( Tcl_Obj *baseObj = opts->baseObj; /* bypass integer recognition if looks like option "-now" */ if ( - (baseObj->length == 4 && baseObj->bytes && *(baseObj->bytes+1) == 'n') || + (baseObj->bytes && baseObj->length == 4 && *(baseObj->bytes+1) == 'n') || TclGetWideIntFromObj(NULL, baseObj, &baseVal) != TCL_OK ) { @@ -3450,17 +3450,19 @@ ClockParseFmtScnArgs( "-now", NULL }; int idx; - if (Tcl_GetIndexFromObj(NULL, baseObj, nowOpts, "seconds or -now", + if (Tcl_GetIndexFromObj(interp, baseObj, nowOpts, "seconds", TCL_EXACT, &idx) == TCL_OK ) { goto baseNow; } - Tcl_SetObjResult(interp, Tcl_ObjPrintf( - "expected integer but got \"%s\"", - TclGetString(baseObj))); - Tcl_SetErrorCode(interp, "TCL", "VALUE", "INTEGER", (char *)NULL); - i = 1; + if (baseObj->typePtr != &tclBignumType) { + Tcl_AppendResult(interp, " or integer", NULL); + } else { + Tcl_SetObjResult(interp, Tcl_ObjPrintf( + "expected integer but got \"%s\"", TclGetString(baseObj))); + } + i = baseIdx; goto badOption; } /* diff --git a/tests/clock.test b/tests/clock.test index b3510fa..b966666 100644 --- a/tests/clock.test +++ b/tests/clock.test @@ -329,8 +329,8 @@ test clock-1.0.1 "clock format - wrong # args (compiled ensemble with invalid sy } [subst {1 {wrong # args: should be "clock format $syntax"} {CLOCK wrongNumArgs}}] test clock-1.1 "clock format - bad time" { - list [catch {clock format foo} msg] $msg -} {1 {expected integer but got "foo"}} + list [catch {clock format foo} msg opt] $msg [dict getd $opt -errorcode {}] +} {1 {bad seconds "foo": must be -now or integer} {CLOCK badOption foo}} test clock-1.2 "clock format - bad gmt val" { list [catch {clock format 0 -gmt foo} msg] $msg @@ -18696,6 +18696,10 @@ test clock-6.8 {input of seconds} { clock scan {9223372036854775807} -format %s -gmt true } 9223372036854775807 +test clock-6.8b "clock scan - bad base" { + list [catch {clock scan "" -base foo -gmt 1} msg opt] $msg [dict getd $opt -errorcode {}] +} {1 {bad seconds "foo": must be -now or integer} {CLOCK badOption foo}} + test clock-6.9 {input of seconds - overflow} { list [catch {clock scan -9223372036854775809 -format %s -gmt true} result opt] $result [dict getd $opt -errorcode ""] } {1 {integer value too large to represent} {CLOCK dateTooLarge}} -- cgit v0.12 From 3eae990587282881a59c302899fd3f67006845c4 Mon Sep 17 00:00:00 2001 From: sebres Date: Sat, 6 Apr 2024 13:48:46 +0000 Subject: more improvements for overflow cases (always proper message, errorCode, correct badOption value) --- generic/tclClock.c | 13 +++++++------ tests/clock.test | 26 ++++++++++++++++++++++---- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/generic/tclClock.c b/generic/tclClock.c index 9aa8242..f79a5b4 100644 --- a/generic/tclClock.c +++ b/generic/tclClock.c @@ -3456,12 +3456,11 @@ ClockParseFmtScnArgs( goto baseNow; } - if (baseObj->typePtr != &tclBignumType) { - Tcl_AppendResult(interp, " or integer", NULL); - } else { - Tcl_SetObjResult(interp, Tcl_ObjPrintf( - "expected integer but got \"%s\"", TclGetString(baseObj))); + if (baseObj->typePtr == &tclBignumType) { + goto baseOverflow; } + + Tcl_AppendResult(interp, " or integer", NULL); i = baseIdx; goto badOption; } @@ -3476,8 +3475,10 @@ ClockParseFmtScnArgs( if ( baseObj->typePtr == &tclBignumType || baseVal < TCL_MIN_SECONDS || baseVal > TCL_MAX_SECONDS ) { +baseOverflow: Tcl_SetObjResult(interp, dataPtr->literals[LIT_INTEGER_VALUE_TOO_LARGE]); - return TCL_ERROR; + i = baseIdx; + goto badOption; } } else { diff --git a/tests/clock.test b/tests/clock.test index b966666..3a43017 100644 --- a/tests/clock.test +++ b/tests/clock.test @@ -38184,14 +38184,32 @@ test clock-61.1 {overflow of a wide integer on output} {*}{ -body { clock format 0x8000000000000000 -format %s -gmt true } - -result {expected integer but got "0x8000000000000000"} + -result {integer value too large to represent} + -errorCode {CLOCK badOption 0x8000000000000000} + -returnCodes error +} +test clock-61.1b {overflow of a wide integer on base} {*}{ + -body { + clock scan "" -base 0x8000000000000000 -gmt true + } + -result {integer value too large to represent} + -errorCode {CLOCK badOption 0x8000000000000000} -returnCodes error } test clock-61.2 {overflow of a wide integer on output} {*}{ -body { clock format -0x8000000000000001 -format %s -gmt true } - -result {expected integer but got "-0x8000000000000001"} + -result {integer value too large to represent} + -errorCode {CLOCK badOption -0x8000000000000001} + -returnCodes error +} +test clock-61.2b {overflow of a wide integer on base} {*}{ + -body { + clock scan "" -base -0x8000000000000001 -gmt true + } + -result {integer value too large to represent} + -errorCode {CLOCK badOption -0x8000000000000001} -returnCodes error } test clock-61.3 {near-miss overflow of a wide integer on output, very large datetime (upper range)} { @@ -38203,10 +38221,10 @@ test clock-61.4 {near-miss overflow of a wide integer on output, very small date test clock-61.5 {overflow of possible date-time (upper range)} -body { clock format 0x00F0000000000001 -gmt true -} -returnCodes error -result {integer value too large to represent} +} -returnCodes error -result {integer value too large to represent} -errorCode {CLOCK badOption 0x00F0000000000001} test clock-61.6 {overflow of possible date-time (lower range)} -body { clock format -0x00F0000000000001 -gmt true -} -returnCodes error -result {integer value too large to represent} +} -returnCodes error -result {integer value too large to represent} -errorCode {CLOCK badOption -0x00F0000000000001} test clock-62.1 {Bug 1902423} {*}{ -setup {::tcl::clock::ClearCaches} -- cgit v0.12