0002-no-memcpy-fallback.patch 3.4 KB

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