Fix memmove() invocation with src/dst being NULL
authorsin <sin@2f30.org>
Wed, 15 Apr 2015 08:43:06 +0000 (09:43 +0100)
committerRoberto E. Vargas Caballero <k0ga@shike2.com>
Wed, 15 Apr 2015 08:51:00 +0000 (10:51 +0200)
This fixes a segmentation fault on some systems.

st.c

diff --git a/st.c b/st.c
index b1d3791..bb8c365 100644 (file)
--- a/st.c
+++ b/st.c
@@ -2788,8 +2788,11 @@ tresize(int col, int row) {
                free(term.line[i]);
                free(term.alt[i]);
        }
-       memmove(term.line, term.line + i, row * sizeof(Line));
-       memmove(term.alt, term.alt + i, row * sizeof(Line));
+       /* ensure that both src and dst are not NULL */
+       if (i > 0) {
+               memmove(term.line, term.line + i, row * sizeof(Line));
+               memmove(term.alt, term.alt + i, row * sizeof(Line));
+       }
        for(i += row; i < term.row; i++) {
                free(term.line[i]);
                free(term.alt[i]);