0001-Do-not-use-memcpy-as-an-alternative-for-bcopy-memmov.patch 3.6 KB

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