[PATCH] Fix memmove() invocation with src/dst being NULL

From: sin <sin_AT_2f30.org>
Date: Wed, 15 Apr 2015 09:43:06 +0100

This fixes a segmentation fault on some systems.
---
 st.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/st.c b/st.c
index b1d3791..bb8c365 100644
--- a/st.c
+++ b/st.c
_AT_@ -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]);
-- 
1.8.4
--wRRV7LY7NUeQGEoC--
Received on Mon Sep 17 2001 - 00:00:00 CEST

This archive was generated by hypermail 2.3.0 : Wed Apr 15 2015 - 10:48:08 CEST