1From: Maarten ter Huurne <maarten@treewalker.org> 2Date: Sat, 13 Sep 2014 11:37:59 +0200 3Subject: Do not use memcpy as an alternative for bcopy/memmove 4 5The configure script runs a small test program to check whether 6memcpy can handle overlapping memory areas. However, it is not valid 7to conclude that if a single case of overlapping memory is handled 8correctly, all cases will be handled correctly. 9 10Since screen already has its own bcopy implementation as a fallback 11for the case that bcopy and memmove are unusable, removing the memcpy 12option should not break any systems. 13 14Signed-off-by: Maarten ter Huurne <maarten@treewalker.org> 15[Ricardo: rebase on top of 4.3.1] 16Signed-off-by: Ricardo Martincoski <ricardo.martincoski@gmail.com> 17[Bernd: rebase on top of 4.7.0] 18Signed-off-by: Bernd Kuhls <bernd.kuhls@t-online.de> 19--- 20 acconfig.h | 3 +-- 21 configure.ac | 18 +----------------- 22 os.h | 8 ++------ 23 osdef.h.in | 10 +--------- 24 4 files changed, 5 insertions(+), 34 deletions(-) 25 26diff --git a/acconfig.h b/acconfig.h 27index 2e46985..9b0b9d4 100644 28--- a/acconfig.h 29+++ b/acconfig.h 30@@ -476,7 +476,7 @@ 31 #undef GETTTYENT 32 33 /* 34- * Define USEBCOPY if the bcopy/memcpy from your system's C library 35+ * Define USEBCOPY if the bcopy from your system's C library 36 * supports the overlapping of source and destination blocks. When 37 * undefined, screen uses its own (probably slower) version of bcopy(). 38 * 39@@ -487,7 +487,6 @@ 40 * Their memove fails the test in the configure script. Sigh. (Juergen) 41 */ 42 #undef USEBCOPY 43-#undef USEMEMCPY 44 #undef USEMEMMOVE 45 46 /* 47diff --git a/configure.ac b/configure.ac 48index 27690a6..b8e3bec 100644 49--- a/configure.ac 50+++ b/configure.ac 51@@ -1145,7 +1145,7 @@ AC_TRY_LINK(,[getttyent();], AC_DEFINE(GETTTYENT)) 52 AC_CHECKING(fdwalk) 53 AC_TRY_LINK([#include <stdlib.h>], [fdwalk(NULL, NULL);],AC_DEFINE(HAVE_FDWALK)) 54 55-AC_CHECKING(whether memcpy/memmove/bcopy handles overlapping arguments) 56+AC_CHECKING(whether memmove/bcopy handles overlapping arguments) 57 AC_TRY_RUN([ 58 main() { 59 char buf[10]; 60@@ -1175,22 +1175,6 @@ main() { 61 exit(0); /* libc version works properly. */ 62 }], AC_DEFINE(USEMEMMOVE)) 63 64- 65-AC_TRY_RUN([ 66-#define bcopy(s,d,l) memcpy(d,s,l) 67-main() { 68- char buf[10]; 69- strcpy(buf, "abcdefghi"); 70- bcopy(buf, buf + 2, 3); 71- if (strncmp(buf, "ababcf", 6)) 72- exit(1); 73- strcpy(buf, "abcdefghi"); 74- bcopy(buf + 2, buf, 3); 75- if (strncmp(buf, "cdedef", 6)) 76- exit(1); 77- exit(0); /* libc version works properly. */ 78-}], AC_DEFINE(USEMEMCPY),,:) 79- 80 AC_SYS_LONG_FILE_NAMES 81 82 AC_MSG_CHECKING(for vsprintf) 83diff --git a/os.h b/os.h 84index e827ac9..0b41fb9 100644 85--- a/os.h 86+++ b/os.h 87@@ -142,12 +142,8 @@ extern int errno; 88 # ifdef USEMEMMOVE 89 # define bcopy(s,d,len) memmove(d,s,len) 90 # else 91-# ifdef USEMEMCPY 92-# define bcopy(s,d,len) memcpy(d,s,len) 93-# else 94-# define NEED_OWN_BCOPY 95-# define bcopy xbcopy 96-# endif 97+# define NEED_OWN_BCOPY 98+# define bcopy xbcopy 99 # endif 100 #endif 101 102diff --git a/osdef.h.in b/osdef.h.in 103index 8687b60..e4057a0 100644 104--- a/osdef.h.in 105+++ b/osdef.h.in 106@@ -58,16 +58,8 @@ extern int bcmp __P((char *, char *, int)); 107 extern int killpg __P((int, int)); 108 #endif 109 110-#ifndef USEBCOPY 111-# ifdef USEMEMCPY 112-extern void memcpy __P((char *, char *, int)); 113-# else 114-# ifdef USEMEMMOVE 115+#if defined(USEMEMMOVE) && !defined(USEBCOPY) 116 extern void memmove __P((char *, char *, int)); 117-# else 118-extern void bcopy __P((char *, char *, int)); 119-# endif 120-# endif 121 #else 122 extern void bcopy __P((char *, char *, int)); 123 #endif 124-- 1251.8.4.5 126 127