diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2022-05-25 10:28:52 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2022-05-25 10:28:52 (GMT) |
commit | 073fb53334ed464e6a989bbfaf2c7bf69e38fdb3 (patch) | |
tree | 5b34e0a916b5c68e2fe35f08a739faa2187586dc /generic | |
parent | ebd247f0bef013b7307aed2d223804205c9c5f70 (diff) | |
parent | f544dd76f2e5c1b1b878c3d683f16f8aab7b6f9e (diff) | |
download | tcl-073fb53334ed464e6a989bbfaf2c7bf69e38fdb3.zip tcl-073fb53334ed464e6a989bbfaf2c7bf69e38fdb3.tar.gz tcl-073fb53334ed464e6a989bbfaf2c7bf69e38fdb3.tar.bz2 |
Fix [76ad7aeba3]: boundary case bug in [string is integer]
Diffstat (limited to 'generic')
-rw-r--r-- | generic/tclCmdMZ.c | 18 | ||||
-rw-r--r-- | generic/tclObj.c | 18 |
2 files changed, 28 insertions, 8 deletions
diff --git a/generic/tclCmdMZ.c b/generic/tclCmdMZ.c index c94abbd..d57dc69 100644 --- a/generic/tclCmdMZ.c +++ b/generic/tclCmdMZ.c @@ -1590,9 +1590,21 @@ StringIsCmd( case STR_IS_GRAPH: chcomp = Tcl_UniCharIsGraph; break; - case STR_IS_INT: - if (TCL_OK == TclGetIntFromObj(NULL, objPtr, &i)) { - break; + case STR_IS_INT: { + void *p; + int type; + if (TCL_OK == TclGetNumberFromObj(NULL, objPtr, &p, &type)) { + if (type == TCL_NUMBER_LONG +#ifndef TCL_WIDE_INT_IS_LONG + || type == TCL_NUMBER_WIDE +#endif + || type == TCL_NUMBER_BIG) { + /* [string is integer] is -UINT_MAX to UINT_MAX range */ + if (TclGetIntFromObj(NULL, objPtr, &i) == TCL_OK) { + break; + } + } + } } goto failedIntParse; case STR_IS_ENTIER: diff --git a/generic/tclObj.c b/generic/tclObj.c index b2fd80b..531a256 100644 --- a/generic/tclObj.c +++ b/generic/tclObj.c @@ -2500,21 +2500,29 @@ Tcl_GetIntFromObj( #if (LONG_MAX == INT_MAX) return TclGetLongFromObj(interp, objPtr, (long *) intPtr); #else - long l; + void *p; + int type; - if (TclGetLongFromObj(interp, objPtr, &l) != TCL_OK) { + if ((TclGetNumberFromObj(NULL, objPtr, &p, &type) != TCL_OK) + || (type == TCL_NUMBER_DOUBLE)) { + if (interp != NULL) { + Tcl_SetObjResult(interp, Tcl_ObjPrintf( + "expected integer but got \"%s\"", Tcl_GetString(objPtr))); + Tcl_SetErrorCode(interp, "TCL", "VALUE", "INTEGER", NULL); + } return TCL_ERROR; } - if ((ULONG_MAX > UINT_MAX) && ((l > UINT_MAX) || (l < -(long)UINT_MAX))) { + if ((type != TCL_NUMBER_LONG) || ((ULONG_MAX > UINT_MAX) + && ((*(long *)p > UINT_MAX) || (*(long *)p < -(long)UINT_MAX)))) { if (interp != NULL) { const char *s = - "integer value too large to represent as non-long integer"; + "integer value too large to represent"; Tcl_SetObjResult(interp, Tcl_NewStringObj(s, -1)); Tcl_SetErrorCode(interp, "ARITH", "IOVERFLOW", s, NULL); } return TCL_ERROR; } - *intPtr = (int) l; + *intPtr = (int)*(long *)p; return TCL_OK; #endif } |