From a55cf1edad4209ab3de602ff4c4a93abb25fce1c Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Mon, 18 Sep 2023 15:50:23 +0000 Subject: Allow larger values for "binary encode base64 -maxlen". Add some more testcases --- generic/tclBinary.c | 4 ++-- tests/binary.test | 6 ++++++ tests/format.test | 6 ++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/generic/tclBinary.c b/generic/tclBinary.c index 3112f02..b6394a4 100644 --- a/generic/tclBinary.c +++ b/generic/tclBinary.c @@ -2701,7 +2701,7 @@ BinaryEncode64( { Tcl_Obj *resultObj; unsigned char *data, *limit; - int maxlen = 0; + Tcl_WideInt maxlen = 0; const char *wrapchar = "\n"; int wrapcharlen = 1; int offset, i, index, size, outindex = 0, count = 0, purewrap = 1; @@ -2720,7 +2720,7 @@ BinaryEncode64( } switch (index) { case OPT_MAXLEN: - if (Tcl_GetIntFromObj(interp, objv[i + 1], &maxlen) != TCL_OK) { + if (Tcl_GetWideIntFromObj(interp, objv[i + 1], &maxlen) != TCL_OK) { return TCL_ERROR; } if (maxlen < 0) { diff --git a/tests/binary.test b/tests/binary.test index 9a309e0..03ef846 100644 --- a/tests/binary.test +++ b/tests/binary.test @@ -2710,6 +2710,12 @@ test binary-72.28 {binary encode base64} -body { test binary-72.29 {binary encode base64} { string length [binary encode base64 -maxlen 3 -wrapchar \xCA abc] } 5 +test binary-72.30 {binary encode base64} { + string length [binary encode base64 -maxlen 4294967296 abc] +} 4 +test binary-72.31 {binary encode base64} -body { + string length [binary encode base64 -maxlen 18446744073709551616 abc] +} -returnCodes 1 -result {integer value too large to represent} test binary-73.1 {binary decode base64} -body { binary decode base64 diff --git a/tests/format.test b/tests/format.test index c5053e8..08490d2 100644 --- a/tests/format.test +++ b/tests/format.test @@ -462,6 +462,12 @@ test format-11.11 {XPG3 %$n specifiers} { test format-11.12 {XPG3 %$n specifiers} { list [catch {format {%2$*d} 4 5 6} msg] $msg } {0 { 6}} +test format-11.13 {XPG3 %$n specifiers} { + format {%2$.*s %4$d} 1 -4294967298 abcdefghijklmnop 44 +} { 44} +test format-11.14 {XPG3 %$n specifiers} { + format {%2$.*s %4$d} 1 4294967298 abcdefghijklmnop 44 +} {abcdefghijklmnop 44} test format-12.1 {negative width specifiers} { format "%*d" -47 25 -- cgit v0.12