From 8f9f88026c8cbb2e4a38b3aa33fb59af5b63d48a Mon Sep 17 00:00:00 2001
From: rswindell <>
Date: Thu, 11 Apr 2019 00:46:08 +0000
Subject: [PATCH] Catch (warn about) safe_snprintf() usage problems when
 building with GCC.

---
 src/xpdev/genwrap.h | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/xpdev/genwrap.h b/src/xpdev/genwrap.h
index da0f91f441..7c26aade24 100644
--- a/src/xpdev/genwrap.h
+++ b/src/xpdev/genwrap.h
@@ -359,7 +359,11 @@ DLLEXPORT long double  	DLLCALL	xp_timer(void);
 DLLEXPORT char*		DLLCALL os_version(char *str);
 DLLEXPORT char*		DLLCALL os_cmdshell(void);
 DLLEXPORT char*		DLLCALL	lastchar(const char* str);
-DLLEXPORT int		DLLCALL safe_snprintf(char *dst, size_t size, const char *fmt, ...);
+DLLEXPORT int		DLLCALL safe_snprintf(char *dst, size_t size, const char *fmt, ...)
+#if defined(__GNUC__)   // Catch printf-format errors
+    __attribute__ ((format (printf, 3 , 4)));            // 1 is 'this'
+#endif
+;
 
 /* C string/char escape-sequence processing */
 DLLEXPORT char*		DLLCALL c_escape_str(const char* src, char* dst, size_t maxlen, BOOL ctrl_only);
-- 
GitLab