From e11bb2b868940d9390510b8b7bbd482f74f4baa7 Mon Sep 17 00:00:00 2001 From: Tatsuya Kinoshita Date: Thu, 4 Mar 2021 22:18:03 +0900 Subject: Consider Strgrow overflow in Strinsert_char --- Str.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Str.c b/Str.c index ab8e4bd..b4f1360 100644 --- a/Str.c +++ b/Str.c @@ -348,10 +348,12 @@ Strinsert_char(Str s, int pos, char c) { int i; STR_LENGTH_CHECK(s); - if (pos < 0 || s->length < pos) + if (pos < 0) return; if (s->length + 2 > s->area_size) Strgrow(s); + if (s->length < pos) + return; for (i = s->length; i > pos; i--) s->ptr[i] = s->ptr[i - 1]; s->ptr[++s->length] = '\0'; -- cgit v1.2.3