[PATCH] Ensure buf[] is always null-terminated after strncpy()

From: sin <sin_AT_2f30.org>
Date: Mon, 1 Dec 2014 20:08:02 +0000

Small style fix as well.
---
 lsw.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lsw.c b/lsw.c
index 9b01f6a..fc40fef 100644
--- a/lsw.c
+++ b/lsw.c
_AT_@ -58,9 +58,9 @@ getname(Window win) {
 	if(!XmbTextPropertyToTextList(dpy, &prop, &list, &n) && n > 0) {
 		strncpy(buf, list[0], sizeof buf);
 		XFreeStringList(list);
-	}
-	else
+	} else
 		strncpy(buf, (char *)prop.value, sizeof buf);
 	XFree(prop.value);
+	buf[sizeof buf - 1] = '\0';
 	return buf;
 }
-- 
1.8.4
--n8g4imXOkfNTN/H1--
Received on Mon Sep 17 2001 - 00:00:00 CEST

This archive was generated by hypermail 2.3.0 : Mon Dec 01 2014 - 21:24:03 CET