commit: f4c510906fb09085bf1f3d32d48980aeb62135a6
parent 5b03749c85a35dbd3b954cd5e727fe84cc33bedb
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Wed, 7 Aug 2024 07:51:53 +0200
cmd/uniq: check cur_len prior to decr it, only free on cur_size>0
Diffstat:
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/cmd/uniq.c b/cmd/uniq.c
@@ -149,7 +149,7 @@ main(int argc, char *argv[])
size_t cur_shift = shift;
- if(cur[cur_len - 1] == '\n')
+ if(cur_len > 0 && cur[cur_len - 1] == '\n')
{
cur[cur_len - 1] = 0;
cur_len--;
@@ -221,7 +221,8 @@ main(int argc, char *argv[])
if(cur_len < 0)
{
- free(cur);
+ if(cur_size > 0) free(cur);
+
break;
}