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); \ } \