diff options
author | dgp <dgp@users.sourceforge.net> | 2018-03-07 15:13:07 (GMT) |
---|---|---|
committer | dgp <dgp@users.sourceforge.net> | 2018-03-07 15:13:07 (GMT) |
commit | 6de6ee8aa9086eb2b86d82e6831dae17232abca4 (patch) | |
tree | 3633d2b708dc8670f3d1b18e1b6ffb2eeecd23b8 /generic/tclScan.c | |
parent | e16df96d28704115312eee43ffc5019a766d2cfd (diff) | |
parent | 0254080ca07929caa2f2b25206928d5559048aff (diff) | |
download | tcl-6de6ee8aa9086eb2b86d82e6831dae17232abca4.zip tcl-6de6ee8aa9086eb2b86d82e6831dae17232abca4.tar.gz tcl-6de6ee8aa9086eb2b86d82e6831dae17232abca4.tar.bz2 |
merge 8.7
Diffstat (limited to 'generic/tclScan.c')
-rw-r--r-- | generic/tclScan.c | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/generic/tclScan.c b/generic/tclScan.c index e0798df..113b4c6 100644 --- a/generic/tclScan.c +++ b/generic/tclScan.c @@ -10,6 +10,7 @@ */ #include "tclInt.h" +#include "tommath.h" /* * Flag values used by Tcl_ScanObjCmd. @@ -415,14 +416,7 @@ ValidateFormat( case 'x': case 'X': case 'b': - break; case 'u': - if (flags & SCAN_BIG) { - Tcl_SetObjResult(interp, Tcl_NewStringObj( - "unsigned bignum scans are invalid", -1)); - Tcl_SetErrorCode(interp, "TCL", "FORMAT", "BADUNSIGNED",NULL); - goto error; - } break; /* * Bracket terms need special checking @@ -932,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)) { @@ -942,9 +936,20 @@ Tcl_ScanObjCmd( (Tcl_WideUInt)wideValue); Tcl_SetStringObj(objPtr, buf, -1); } else { - Tcl_SetWideIntObj(objPtr, wideValue); + TclSetIntObj(objPtr, wideValue); } - } else if (!(flags & SCAN_BIG)) { + } else if (flags & SCAN_BIG) { + if (flags & SCAN_UNSIGNED) { + mp_int big; + if ((Tcl_GetBignumFromObj(interp, objPtr, &big) != TCL_OK) + || mp_isneg(&big)) { + Tcl_SetObjResult(interp, Tcl_NewStringObj( + "unsigned bignum scans are invalid", -1)); + Tcl_SetErrorCode(interp, "TCL", "FORMAT", "BADUNSIGNED",NULL); + return TCL_ERROR; + } + } + } else { if (TclGetLongFromObj(NULL, objPtr, &value) != TCL_OK) { if (TclGetString(objPtr)[0] == '-') { value = LONG_MIN; @@ -956,7 +961,7 @@ Tcl_ScanObjCmd( sprintf(buf, "%lu", value); /* INTL: ISO digit */ Tcl_SetStringObj(objPtr, buf, -1); } else { - Tcl_SetLongObj(objPtr, value); + TclSetIntObj(objPtr, value); } } objs[objIndex++] = objPtr; |