From 553caf0d2c710467bff3d7916f6e2e50e899768f Mon Sep 17 00:00:00 2001 From: apnadkarni Date: Mon, 24 Apr 2023 16:49:34 +0000 Subject: Fix [9369f83649] - binary format/scan for big data --- generic/tclBinary.c | 14 +++++++------- tests/bigdata.test | 16 +++++++++------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/generic/tclBinary.c b/generic/tclBinary.c index 3a9d62e..e0bfd46 100644 --- a/generic/tclBinary.c +++ b/generic/tclBinary.c @@ -870,7 +870,7 @@ BinaryFormatCmd( int value = 0; /* Current integer value to be packed. * Initialized to avoid compiler warning. */ char cmd; /* Current format character. */ - Tcl_Size count; /* Count associated with current format + Tcl_Size count; /* Count associated with current format * character. */ int flags; /* Format field flags */ const char *format; /* Pointer to current position in format @@ -1383,7 +1383,7 @@ BinaryScanCmd( int value = 0; /* Current integer value to be packed. * Initialized to avoid compiler warning. */ char cmd; /* Current format character. */ - Tcl_Size count; /* Count associated with current format + Tcl_Size count; /* Count associated with current format * character. */ int flags; /* Format field flags */ const char *format; /* Pointer to current position in format @@ -1795,14 +1795,14 @@ GetFormatSpec( (*formatPtr)++; *countPtr = BINARY_ALL; } else if (isdigit(UCHAR(**formatPtr))) { /* INTL: digit */ - unsigned long count; + unsigned long long count; errno = 0; - count = strtoul(*formatPtr, (char **) formatPtr, 10); - if (errno || (count > (unsigned long) INT_MAX)) { - *countPtr = INT_MAX; + count = strtoull(*formatPtr, (char **) formatPtr, 10); + if (errno || (count > TCL_SIZE_MAX)) { + *countPtr = TCL_SIZE_MAX; } else { - *countPtr = (int) count; + *countPtr = count; } } else { *countPtr = BINARY_NOCOUNT; diff --git a/tests/bigdata.test b/tests/bigdata.test index d368685..ab4335b 100644 --- a/tests/bigdata.test +++ b/tests/bigdata.test @@ -681,16 +681,17 @@ bigtestRO subst-bigdata-1 "subst" {1 1} -body { # # binary format -bigtestRO binary-format-bigdata-1 "binary format aN" 4294967296 -body { +bigtestRO binary-format-bigdata-1 "binary format aN" [list 4294967296 X\0\0\0 \0\0\0\0] -body { # Unset explicitly before setting to save memory as bigtestRO runs the # script below twice. unset -nocomplain bin set bin [binary format a4294967296 X] - string length $bin + list [string length $bin] [string range $bin 0 3] [string range $bin end-3 end] } -cleanup { bigClean -} -constraints bug-9369f83649 -# TODO - do string compare and add other format specifiers once above bug is fixed +} +# -constraints bug-9369f83649 +# TODO - do string compare and add other format specifiers bigtestRO binary-format-bigdata-2 "binary format a*" 1 -body { # Unset explicitly before setting to save memory as bigtestRO runs the @@ -706,17 +707,18 @@ bigtestRO binary-format-bigdata-2 "binary format a*" 1 -body { # # binary scan -bigtestRO binary-scan-bigdata-1 "binary scan aN" 4294967296 -body { +bigtestRO binary-scan-bigdata-1 "binary scan aN" {4294967296 0123 2345} -body { # Unset explicitly before setting to save memory as bigtestRO runs the # script below twice. unset -nocomplain bin2 binary scan $bin a4294967296 bin2 - string length $bin2 + list [string length $bin2] [string range $bin2 0 3] [string range $bin2 end-3 end] } -setup { set bin [bigBinary 4294967296] } -cleanup { bigClean -} -constraints bug-9369f83649 +} +# -constraints bug-9369f83649 # TODO - do string compare and add other format specifiers once above bug is fixed bigtestRO binary-scan-bigdata-2 "binary scan a*" 1 -body { -- cgit v0.12