summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2017-04-05 08:41:48 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2017-04-05 08:41:48 (GMT)
commitea8cb9b7bbc9be827be479c3aad3700cbe5774a4 (patch)
tree679b353959d9797b0c59459c42491f6326c65a9d /generic
parentd10ba45b4b07890f74e2625560bfb21e8099e2d4 (diff)
downloadtcl-ea8cb9b7bbc9be827be479c3aad3700cbe5774a4.zip
tcl-ea8cb9b7bbc9be827be479c3aad3700cbe5774a4.tar.gz
tcl-ea8cb9b7bbc9be827be479c3aad3700cbe5774a4.tar.bz2
Fix [4b12ccb3363e81b132e8dbe12aeec596102be1a8|4b12ccb336]: format/scan %llu doesn't work. Also added new test-cases showing the expected behavior.
Diffstat (limited to 'generic')
-rw-r--r--generic/tclScan.c21
-rw-r--r--generic/tclStringObj.c14
2 files changed, 22 insertions, 13 deletions
diff --git a/generic/tclScan.c b/generic/tclScan.c
index 3edb8be..5ea7e46 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
@@ -936,7 +930,18 @@ Tcl_ScanObjCmd(
} else {
Tcl_SetWideIntObj(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_cmp_d(&big, 0) == MP_LT)) {
+ 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;
diff --git a/generic/tclStringObj.c b/generic/tclStringObj.c
index 4e19750..6cce073 100644
--- a/generic/tclStringObj.c
+++ b/generic/tclStringObj.c
@@ -1943,11 +1943,6 @@ Tcl_AppendFormatToObj(
}
case 'u':
- if (useBig) {
- msg = "unsigned bignum format is invalid";
- errCode = "BADUNSIGNED";
- goto errorMsg;
- }
case 'd':
case 'o':
case 'x':
@@ -1965,6 +1960,15 @@ Tcl_AppendFormatToObj(
goto error;
}
isNegative = (mp_cmp_d(&big, 0) == MP_LT);
+ if (ch == 'u') {
+ if (isNegative) {
+ msg = "unsigned bignum format is invalid";
+ errCode = "BADUNSIGNED";
+ goto errorMsg;
+ } else {
+ ch = 'd';
+ }
+ }
#ifndef TCL_WIDE_INT_IS_LONG
} else if (useWide) {
if (Tcl_GetWideIntFromObj(NULL, segment, &w) != TCL_OK) {