diff options
| author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2018-09-04 14:37:01 (GMT) |
|---|---|---|
| committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2018-09-04 14:37:01 (GMT) |
| commit | fdf1df3b29531c5031a33f2e3c1f4668937c1c5f (patch) | |
| tree | 3d2e88bf613d6b66d0fb2a83c382f0e9aa0c24dc /generic/tclStringObj.c | |
| parent | 2f2b7f6ac7122f3b6be07e793e1658cdb5791aa2 (diff) | |
| download | tcl-fdf1df3b29531c5031a33f2e3c1f4668937c1c5f.zip tcl-fdf1df3b29531c5031a33f2e3c1f4668937c1c5f.tar.gz tcl-fdf1df3b29531c5031a33f2e3c1f4668937c1c5f.tar.bz2 | |
Fix [540bed4bde]: binary format can result in "integer value too large to represent".
Implemented a new utility function TclGetWideBitsFromObj(), which handles the overflowing of integers using bignums.
This function can be used in a _LOT_ of other places, preventing code duplication. Done that as well.
Those changes have no effect on other commands, only two new "binary format" test-cases for this specific situation: binary-44.5 and binary-44.6
Diffstat (limited to 'generic/tclStringObj.c')
| -rw-r--r-- | generic/tclStringObj.c | 26 |
1 files changed, 4 insertions, 22 deletions
diff --git a/generic/tclStringObj.c b/generic/tclStringObj.c index f98180f..f238268 100644 --- a/generic/tclStringObj.c +++ b/generic/tclStringObj.c @@ -2097,33 +2097,15 @@ Tcl_AppendFormatToObj( } #ifndef TCL_WIDE_INT_IS_LONG } else if (useWide) { - if (TclGetWideIntFromObj(NULL, segment, &w) != TCL_OK) { - Tcl_Obj *objPtr; - - if (Tcl_GetBignumFromObj(interp,segment,&big) != TCL_OK) { - goto error; - } - mp_mod_2d(&big, (int) CHAR_BIT*sizeof(Tcl_WideInt), &big); - objPtr = Tcl_NewBignumObj(&big); - Tcl_IncrRefCount(objPtr); - TclGetWideIntFromObj(NULL, objPtr, &w); - Tcl_DecrRefCount(objPtr); + if (TclGetWideBitsFromObj(interp, segment, &w) != TCL_OK) { + goto error; } isNegative = (w < (Tcl_WideInt) 0); if (w == (Tcl_WideInt) 0) gotHash = 0; #endif } else if (TclGetLongFromObj(NULL, segment, &l) != TCL_OK) { - if (TclGetWideIntFromObj(NULL, segment, &w) != TCL_OK) { - Tcl_Obj *objPtr; - - if (Tcl_GetBignumFromObj(interp,segment,&big) != TCL_OK) { - goto error; - } - mp_mod_2d(&big, (int) CHAR_BIT * sizeof(long), &big); - objPtr = Tcl_NewBignumObj(&big); - Tcl_IncrRefCount(objPtr); - TclGetLongFromObj(NULL, objPtr, &l); - Tcl_DecrRefCount(objPtr); + if (TclGetWideBitsFromObj(interp, segment, &w) != TCL_OK) { + goto error; } else { l = Tcl_WideAsLong(w); } |
