From cab4bde6e1f2ac125859f605a2e95109c4aa3e47 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Sat, 26 Jul 2003 09:10:45 +0000 Subject: (parse_tabstops): Detect overflow properly. --- src/expand.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/expand.c') diff --git a/src/expand.c b/src/expand.c index fcd35429b..8be52b563 100644 --- a/src/expand.c +++ b/src/expand.c @@ -173,10 +173,11 @@ parse_tabstops (char const *stops) num_start = stops; } { + int new_t; + /* Detect overflow. */ - int prev = tabval; - tabval = tabval * 10 + *stops - '0'; - if (tabval < prev) + new_t = 10 * tabval + *stops - '0'; + if (INT_MAX / 10 < tabval || new_t < tabval * 10) { size_t len = strspn (num_start, "0123456789"); char *bad_num = xstrndup (num_start, len); @@ -184,6 +185,7 @@ parse_tabstops (char const *stops) fail = 1; stops = num_start + len - 1; } + tabval = new_t; } } else -- cgit v1.2.3-54-g00ecf