bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] braces: avoid signed overflow


From: Grisha Levit
Subject: [PATCH] braces: avoid signed overflow
Date: Tue, 1 Oct 2024 19:18:14 -0400

INTMAX_MAX=9223372036854775807
eval ": {$((INTMAX_MAX-1))..$((INTMAX_MAX))}"

braces.c:447:9: runtime error: signed integer overflow: 9223372036854775807 + 1 
cannot be represented in type 'intmax_t' (aka 'long')
---
 braces.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/braces.c b/braces.c
index 099312e4..e73f5219 100644
--- a/braces.c
+++ b/braces.c
@@ -444,9 +444,11 @@ mkseq (intmax_t start, intmax_t end, intmax_t incr, int 
type, size_t width)
          return ((char **)NULL);
        }
 
+      if (i >= nelem - 1)
+       break;
       n += incr;
     }
-  while (i < nelem - 1);
+  while (1);
 
   result[i] = (char *)0;
   return (result);
-- 
2.46.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]