From 555206cf6041c0ab8c83f3a9860cd794a7be255c Mon Sep 17 00:00:00 2001
From: Dominique Martinet <asmadeus@codewreck.org>
Date: Thu, 5 Apr 2018 13:58:23 +0900
Subject: Fix gcc string truncation warnings

---
 examples/support/config.c | 5 ++++-
 examples/support/ini.c    | 2 +-
 2 files changed, 5 insertions(+), 2 deletions(-)

(limited to 'examples/support')

diff --git a/examples/support/config.c b/examples/support/config.c
index f0efa594..319be31a 100644
--- a/examples/support/config.c
+++ b/examples/support/config.c
@@ -202,7 +202,10 @@ struct example_config *parse_args(int argc, char *argv[]) {
 		char cwd[MAXPATHLEN];
 		if (getcwd(cwd, sizeof(cwd)) != NULL) {
 			char buf[MAXPATHLEN];
-			snprintf(buf, MAXPATHLEN, "%s/%s", cwd, "wlr-example.ini");
+			if (snprintf(buf, MAXPATHLEN, "%s/%s", cwd, "wlr-example.ini") >= MAXPATHLEN) {
+				wlr_log(L_ERROR, "config path too long");
+				exit(1);
+			}
 			config->config_path = strdup(buf);
 		} else {
 			wlr_log(L_ERROR, "could not get cwd");
diff --git a/examples/support/ini.c b/examples/support/ini.c
index 6be9c44a..6bc1eae6 100644
--- a/examples/support/ini.c
+++ b/examples/support/ini.c
@@ -64,7 +64,7 @@ static char* find_chars_or_comment(const char* s, const char* chars)
 /* Version of strncpy that ensures dest (size bytes) is null-terminated. */
 static char* strncpy0(char* dest, const char* src, size_t size)
 {
-    strncpy(dest, src, size);
+    strncpy(dest, src, size-1);
     dest[size - 1] = '\0';
     return dest;
 }
-- 
cgit v1.2.3