diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2022-05-22 17:11:58 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2022-05-22 17:11:58 (GMT) |
commit | 393936e2b829ec47b742c3225bb29250a8e728b8 (patch) | |
tree | 9e3c2fbb691e02ea80a48f8073b6028042246971 /generic/tclObj.c | |
parent | 185db606f066a1ec6904691d6446ef62e184f674 (diff) | |
download | tcl-393936e2b829ec47b742c3225bb29250a8e728b8.zip tcl-393936e2b829ec47b742c3225bb29250a8e728b8.tar.gz tcl-393936e2b829ec47b742c3225bb29250a8e728b8.tar.bz2 |
Proposed fix for [76ad7aeba3]: boundary case bug in [string is integer]. Missing: more unit-tests
Diffstat (limited to 'generic/tclObj.c')
-rw-r--r-- | generic/tclObj.c | 18 |
1 files changed, 13 insertions, 5 deletions
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 } |