From 5d3fa03acb4059e3ce79cfea50650d0b7c81268c Mon Sep 17 00:00:00 2001
From: deuce <>
Date: Fri, 7 Apr 2006 07:08:37 +0000
Subject: [PATCH] Fix SAFECOPY() macro to not copy if src==dst (Found by
 Valgrind)

---
 src/xpdev/gen_defs.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/xpdev/gen_defs.h b/src/xpdev/gen_defs.h
index c93cce76af..99053e8b89 100644
--- a/src/xpdev/gen_defs.h
+++ b/src/xpdev/gen_defs.h
@@ -237,7 +237,7 @@ typedef struct {
 #ifdef SAFECOPY_USES_SPRINTF
 #define SAFECOPY(dst,src)				sprintf(dst,"%.*s",(int)sizeof(dst)-1,src)
 #else
-#define SAFECOPY(dst,src)				(strncpy(dst,src,sizeof(dst)), dst[(int)sizeof(dst)-1]=0)
+#define SAFECOPY(dst,src)				(((dst)==(src))?0:(strncpy(dst,src,sizeof(dst)), dst[(int)sizeof(dst)-1]=0))
 #endif
 #define TERMINATE(str)					str[sizeof(str)-1]=0
 #if (defined __FreeBSD__) || (defined __NetBSD__) || (defined __OpenBSD__) || (defined(__APPLE__) && defined(__MACH__) && defined(__POWERPC__))
-- 
GitLab