LogoopenSUSE Build Service > Projects
Sign Up | Log In

View File 1145-erts-Fix-some-zero-size-sys_memcpy.patch of Package erlang (Project home:Ledest:erlang:20)

From 1ac8caa8d22f3767e84e7be749afbd5ed17a11b4 Mon Sep 17 00:00:00 2001
From: Sverker Eriksson <sverker@erlang.org>
Date: Tue, 20 Mar 2018 16:48:26 +0100
Subject: [PATCH] erts: Fix some zero size sys_memcpy

---
 erts/emulator/beam/erl_bits.h         | 2 +-
 erts/emulator/beam/sys.h              | 4 +---
 erts/emulator/hipe/hipe_mode_switch.c | 3 ++-
 3 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/erts/emulator/beam/erl_bits.h b/erts/emulator/beam/erl_bits.h
index b9d141d585..a3816fa820 100644
--- a/erts/emulator/beam/erl_bits.h
+++ b/erts/emulator/beam/erl_bits.h
@@ -111,7 +111,7 @@ typedef struct erl_bin_match_struct{
 #define copy_binary_to_buffer(DstBuffer, DstBufOffset, SrcBuffer, SrcBufferOffset, NumBits) \
   do {											    \
     if (BIT_OFFSET(DstBufOffset) == 0 && (SrcBufferOffset == 0) &&			    \
-        (BIT_OFFSET(NumBits)==0)) {							    \
+        (BIT_OFFSET(NumBits)==0) && (NumBits != 0)) {					    \
       sys_memcpy(DstBuffer+BYTE_OFFSET(DstBufOffset),					    \
 		 SrcBuffer, NBYTES(NumBits));						    \
     } else {										    \
diff --git a/erts/emulator/beam/sys.h b/erts/emulator/beam/sys.h
index 152da8c9e1..c21acadd8d 100644
--- a/erts/emulator/beam/sys.h
+++ b/erts/emulator/beam/sys.h
@@ -1004,9 +1004,7 @@ erts_refc_read(erts_refc_t *refcp, erts_aint_t min_val)
  * may seemingly work when the length (if any) is zero; a compiler can take
  * this as a hint that the passed operand may *never* be NULL and then optimize
  * based on that information.
- *
- * (The weird casts in the assertions silence an "always evaluates to true"
- * warning when an operand is the address of an lvalue) */
+ */
 ERTS_GLB_INLINE void *sys_memcpy(void *dest, const void *src, size_t n);
 ERTS_GLB_INLINE void *sys_memmove(void *dest, const void *src, size_t n);
 ERTS_GLB_INLINE int sys_memcmp(const void *s1, const void *s2, size_t n);
diff --git a/erts/emulator/hipe/hipe_mode_switch.c b/erts/emulator/hipe/hipe_mode_switch.c
index 8b497c9970..f2befb07e3 100644
--- a/erts/emulator/hipe/hipe_mode_switch.c
+++ b/erts/emulator/hipe/hipe_mode_switch.c
@@ -662,7 +662,8 @@ void hipe_inc_nstack(Process *p)
     Eterm *new_nstack = erts_alloc(ERTS_ALC_T_HIPE_STK, new_size*sizeof(Eterm));
     unsigned used_size = p->hipe.nstend - p->hipe.nsp;
 
-    sys_memcpy(new_nstack+new_size-used_size, p->hipe.nsp, used_size*sizeof(Eterm));
+    if (used_size)
+        sys_memcpy(new_nstack+new_size-used_size, p->hipe.nsp, used_size*sizeof(Eterm));
     if (p->hipe.nstgraylim)
 	p->hipe.nstgraylim = new_nstack + new_size - (p->hipe.nstend - p->hipe.nstgraylim);
     if (p->hipe.nstblacklim)
-- 
2.16.3