summaryrefslogtreecommitdiffstats
path: root/generic/tclScan.c
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2019-11-08 09:01:43 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2019-11-08 09:01:43 (GMT)
commit5de9b738d3fc73ba62f781f55ba8891ccec9764a (patch)
tree2dfe8e46cde63cf66758cd794762d3c26ea99ce3 /generic/tclScan.c
parent2325ddede0d49a1700d83457e8e36da87e548ccf (diff)
parent65946d3f86dd49b65b128b71d4b2c4b4a020a277 (diff)
downloadtcl-5de9b738d3fc73ba62f781f55ba8891ccec9764a.zip
tcl-5de9b738d3fc73ba62f781f55ba8891ccec9764a.tar.gz
tcl-5de9b738d3fc73ba62f781f55ba8891ccec9764a.tar.bz2
Merge 8.6.
Add support for libtommath's mp_set_ll() function, since that's the replacement for the deprecated TclBNInitBignumFromWideInt() function.
Diffstat (limited to 'generic/tclScan.c')
-rw-r--r--generic/tclScan.c31
1 files changed, 24 insertions, 7 deletions
diff --git a/generic/tclScan.c b/generic/tclScan.c
index f481cc9..5edbffa 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);
}
@@ -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);
}