From e9c0312caf99f93393a446302d67b7bcafeca575 Mon Sep 17 00:00:00 2001 From: dgp Date: Thu, 1 Mar 2018 04:13:15 +0000 Subject: We have LLONG_MIN and LLONG_MAX to denote range limits of Tcl_WideInt. Use them consistently. Also fix a few TIP 484 bugs. --- generic/tclExecute.c | 26 +++++++++++++------------- generic/tclScan.c | 4 ++-- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/generic/tclExecute.c b/generic/tclExecute.c index 1c69474..09b03bd 100644 --- a/generic/tclExecute.c +++ b/generic/tclExecute.c @@ -5766,17 +5766,17 @@ TEBCresume( if (GetNumberFromObj(NULL, OBJ_AT_TOS, &ptr1, &type1) != TCL_OK) { type1 = 0; } else if (type1 == TCL_NUMBER_WIDE) { - /* value is between WIDE_MIN and WIDE_MAX */ + /* value is between LLONG_MIN and LLONG_MAX */ /* [string is integer] is -UINT_MAX to UINT_MAX range */ - /* [string is wideinteger] is -UWIDE_MAX to UWIDE_MAX range */ + /* [string is wideinteger] is -ULLONG_MAX to ULLONG_MAX range */ int i; if (Tcl_GetIntFromObj(NULL, OBJ_AT_TOS, &i) == TCL_OK) { type1 = TCL_NUMBER_LONG; } } else if (type1 == TCL_NUMBER_BIG) { - /* value is an integer outside the WIDE_MIN to WIDE_MAX range */ - /* [string is wideinteger] is -UWIDE_MAX to UWIDE_MAX range */ + /* value is an integer outside the LLONG_MIN to LLONG_MAX range */ + /* [string is wideinteger] is -ULLONG_MAX to ULLONG_MAX range */ Tcl_WideInt w; if (Tcl_GetWideIntFromObj(NULL, OBJ_AT_TOS, &w) == TCL_OK) { @@ -6007,7 +6007,7 @@ TEBCresume( objResultPtr = TCONST(0); TRACE(("%s\n", O2S(objResultPtr))); NEXT_INST_F(1, 2, 1); - } else if (w2 > (Tcl_WideInt) INT_MAX) { + } else if (w2 > INT_MAX) { /* * Technically, we could hold the value (1 << (INT_MAX+1)) * in an mp_int, but since we're using mp_mul_2d() to do @@ -6186,7 +6186,7 @@ TEBCresume( goto divideByZero; } else if ((w1 == LLONG_MIN) && (w2 == -1)) { /* - * Can't represent (-LLONG_MIN) as a long. + * Can't represent (-LLONG_MIN) as a Tcl_WideInt. */ goto overflow; @@ -6206,10 +6206,10 @@ TEBCresume( goto wideResultOfArithmetic; case INST_MULT: - if (((sizeof(long) >= 2*sizeof(int)) + if (((sizeof(Tcl_WideInt) >= 2*sizeof(int)) && (w1 <= INT_MAX) && (w1 >= INT_MIN) && (w2 <= INT_MAX) && (w2 >= INT_MIN)) - || ((sizeof(long) >= 2*sizeof(short)) + || ((sizeof(Tcl_WideInt) >= 2*sizeof(short)) && (w1 <= SHRT_MAX) && (w1 >= SHRT_MIN) && (w2 <= SHRT_MAX) && (w2 >= SHRT_MIN))) { wResult = w1 * w2; @@ -8123,7 +8123,7 @@ ExecuteExtendedBinaryMathOp( */ if ((type2 != TCL_NUMBER_WIDE) - || (*((const Tcl_WideInt *)ptr2) > (long) INT_MAX)) { + || (*((const Tcl_WideInt *)ptr2) > INT_MAX)) { /* * Technically, we could hold the value (1 << (INT_MAX+1)) in * an mp_int, but since we're using mp_mul_2d() to do the @@ -8985,10 +8985,10 @@ TclCompareTwoNumbers( * integer comparison can tell the difference. */ - if (d2 < (double)LONG_MIN) { + if (d2 < (double)LLONG_MIN) { return MP_GT; } - if (d2 > (double)LONG_MAX) { + if (d2 > (double)LLONG_MAX) { return MP_LT; } w2 = (Tcl_WideInt) d2; @@ -9031,7 +9031,7 @@ TclCompareTwoNumbers( return (d1 > 0.0) ? MP_GT : MP_LT; } Tcl_TakeBignumFromObj(NULL, value2Ptr, &big2); - if ((d1 < (double)LONG_MAX) && (d1 > (double)LONG_MIN)) { + if ((d1 < (double)LLONG_MAX) && (d1 > (double)LLONG_MIN)) { if (mp_isneg(&big2)) { compare = MP_GT; } else { @@ -9064,7 +9064,7 @@ TclCompareTwoNumbers( mp_clear(&big1); return compare; } - if ((d2 < (double)LONG_MAX) && (d2 > (double)LONG_MIN)) { + if ((d2 < (double)LLONG_MAX) && (d2 > (double)LLONG_MIN)) { compare = mp_cmp_d(&big1, 0); mp_clear(&big1); return compare; diff --git a/generic/tclScan.c b/generic/tclScan.c index d55d29b..113b4c6 100644 --- a/generic/tclScan.c +++ b/generic/tclScan.c @@ -926,9 +926,9 @@ Tcl_ScanObjCmd( } if (flags & SCAN_LONGER) { if (Tcl_GetWideIntFromObj(NULL, objPtr, &wideValue) != TCL_OK) { - wideValue = ~(Tcl_WideUInt)0 >> 1; /* WIDE_MAX */ + wideValue = LLONG_MAX; if (TclGetString(objPtr)[0] == '-') { - wideValue++; /* WIDE_MAX + 1 = WIDE_MIN */ + wideValue = LLONG_MIN; } } if ((flags & SCAN_UNSIGNED) && (wideValue < 0)) { -- cgit v0.12