diff options
Diffstat (limited to 'generic/tclScan.c')
-rw-r--r-- | generic/tclScan.c | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/generic/tclScan.c b/generic/tclScan.c index ba9ccbe..6f9515b 100644 --- a/generic/tclScan.c +++ b/generic/tclScan.c @@ -579,9 +579,6 @@ Tcl_ScanObjCmd( Tcl_UniChar ch = 0, sch = 0; Tcl_Obj **objs = NULL, *objPtr = NULL; int flags; - char buf[513]; /* Temporary buffer to hold scanned number - * strings before they are passed to - * strtoul. */ if (objc < 3) { Tcl_WrongNumArgs(interp, 1, objv, @@ -931,8 +928,16 @@ Tcl_ScanObjCmd( } } if ((flags & SCAN_UNSIGNED) && (wideValue < 0)) { - sprintf(buf, "%" TCL_LL_MODIFIER "u", wideValue); - Tcl_SetStringObj(objPtr, buf, -1); + mp_int big; + if (mp_init(&big) != MP_OKAY) { + Tcl_SetObjResult(interp, Tcl_NewStringObj( + "insufficient memory to create bignum", -1)); + Tcl_SetErrorCode(interp, "TCL", "MEMORY", NULL); + return TCL_ERROR; + } else { + mp_set_ull(&big, (Tcl_WideUInt)wideValue); + Tcl_SetBignumObj(objPtr, &big); + } } else { TclSetIntObj(objPtr, wideValue); } @@ -942,7 +947,7 @@ Tcl_ScanObjCmd( int code = Tcl_GetBignumFromObj(interp, objPtr, &big); if (code == TCL_OK) { - if (big.sign != MP_ZPOS) { + if (mp_isneg(&big)) { code = TCL_ERROR; } mp_clear(&big); @@ -969,8 +974,20 @@ Tcl_ScanObjCmd( } } if ((flags & SCAN_UNSIGNED) && (value < 0)) { - sprintf(buf, "%lu", value); /* INTL: ISO digit */ - Tcl_SetStringObj(objPtr, buf, -1); +#ifdef TCL_WIDE_INT_IS_LONG + mp_int big; + if (mp_init(&big) != MP_OKAY) { + Tcl_SetObjResult(interp, Tcl_NewStringObj( + "insufficient memory to create bignum", -1)); + Tcl_SetErrorCode(interp, "TCL", "MEMORY", NULL); + return TCL_ERROR; + } else { + mp_set_ull(&big, (unsigned long)value); + Tcl_SetBignumObj(objPtr, &big); + } +#else + Tcl_SetWideIntObj(objPtr, (unsigned long)value); +#endif } else { TclSetIntObj(objPtr, value); } |