summaryrefslogtreecommitdiffstats
path: root/generic/tclBinary.c
diff options
context:
space:
mode:
Diffstat (limited to 'generic/tclBinary.c')
-rw-r--r--generic/tclBinary.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/generic/tclBinary.c b/generic/tclBinary.c
index 68289f2..cbe4970 100644
--- a/generic/tclBinary.c
+++ b/generic/tclBinary.c
@@ -1528,7 +1528,15 @@ GetFormatSpec(
(*formatPtr)++;
(*countPtr) = BINARY_ALL;
} else if (isdigit(UCHAR(**formatPtr))) { /* INTL: digit */
- (*countPtr) = strtoul(*formatPtr, formatPtr, 10);
+ unsigned long int count;
+
+ errno = 0;
+ count = strtoul(*formatPtr, formatPtr, 10);
+ if (errno || (count > (unsigned long) INT_MAX)) {
+ (*countPtr) = INT_MAX;
+ } else {
+ (*countPtr) = (int) count;
+ }
} else {
(*countPtr) = BINARY_NOCOUNT;
}