From 966cd45834093c868ccf3534dee6b6ff4beae515 Mon Sep 17 00:00:00 2001
From: rswindell <>
Date: Fri, 7 Apr 2006 21:12:34 +0000
Subject: [PATCH] Remove the src==dst comparison in SAFECOPY() - we want
 Valgrind to find occurances of these calls and report them (they're bugs).
 Use the TERMINATE function in the strncpy version of SAFECOPY() (does it need
 the int-typecast Deuce?).

---
 src/xpdev/gen_defs.h | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/xpdev/gen_defs.h b/src/xpdev/gen_defs.h
index 3f0ee08e61..1e405f49ec 100644
--- a/src/xpdev/gen_defs.h
+++ b/src/xpdev/gen_defs.h
@@ -233,13 +233,17 @@ typedef struct {
 /* Handy String Macros */
 /***********************/
 
+/* Null-Terminate an ASCIIZ char array */
+#define TERMINATE(str)					str[sizeof(str)-1]=0
+
 /* This is a bound-safe version of strcpy basically - only works with fixed-length arrays */
 #ifdef SAFECOPY_USES_SPRINTF
 #define SAFECOPY(dst,src)				sprintf(dst,"%.*s",(int)sizeof(dst)-1,src)
-#else
-#define SAFECOPY(dst,src)				((((char *)(dst))==((char *)(src)))?0:(strncpy(dst,src,sizeof(dst)), dst[(int)sizeof(dst)-1]=0))
+#else	/* strncpy is faster */
+#define SAFECOPY(dst,src)				(strncpy(dst,src,sizeof(dst)), TERMINATE(dst))
 #endif
-#define TERMINATE(str)					str[sizeof(str)-1]=0
+
+/* Bound-safe version of sprintf() - only works with fixed-length arrays */
 #if (defined __FreeBSD__) || (defined __NetBSD__) || (defined __OpenBSD__) || (defined(__APPLE__) && defined(__MACH__) && defined(__POWERPC__))
 /* *BSD *nprintf() is already safe */
 #define SAFEPRINTF(dst,fmt,arg)			snprintf(dst,sizeof(dst),fmt,arg)
-- 
GitLab