From 8164da9e3e3a679bfa94b477674882922d6e28c8 Mon Sep 17 00:00:00 2001 From: Tatsuya Kinoshita Date: Sun, 4 Aug 2013 16:27:00 +0900 Subject: Check length for Strchop() --- Str.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Str.c') diff --git a/Str.c b/Str.c index e5a0982..eff82a4 100644 --- a/Str.c +++ b/Str.c @@ -278,8 +278,8 @@ void Strchop(Str s) { STR_LENGTH_CHECK(s); - while ((s->ptr[s->length - 1] == '\n' || s->ptr[s->length - 1] == '\r') && - s->length > 0) { + while (s->length > 0 && + (s->ptr[s->length - 1] == '\n' || s->ptr[s->length - 1] == '\r')) { s->length--; } s->ptr[s->length] = '\0'; -- cgit v1.2.3