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