From a14612d96819d5e0561bff2da89a6fdea990223c Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Tue, 23 Aug 2022 23:49:34 +0200 Subject: [PATCH] setmode: Dot not use saveset after free While we are only doing a pointer difference and not dereferencing it, it's easier and more correct to do the pointer difference before passing it to reallocarray(). Warned-by: gcc --- src/setmode.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/setmode.c b/src/setmode.c index f65875e..c92cdc5 100644 --- a/src/setmode.c +++ b/src/setmode.c @@ -36,6 +36,7 @@ #include #include +#include #include #include #include @@ -144,12 +145,13 @@ common: if (set->cmd2 & CMD2_CLR) { #define ADDCMD(a, b, c, d) do { \ if (set >= endset) { \ + ptrdiff_t setdiff = set - saveset; \ BITCMD *newset; \ setlen += SET_LEN_INCR; \ newset = reallocarray(saveset, setlen, sizeof(BITCMD)); \ if (newset == NULL) \ goto out; \ - set = newset + (set - saveset); \ + set = newset + setdiff; \ saveset = newset; \ endset = newset + (setlen - 2); \ } \