From 03a2d33363262ebd29de7e7bf86485b068488883 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