Skip to content

Commit 0045848

Browse files
committed
assert under DEBUGGING that Copy's arguments don't overlap
memcpy() has undefined behavior if the source/destination ranges overlap, so assert that they don't.
1 parent 816209d commit 0045848

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

handy.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2867,6 +2867,11 @@ enum mem_log_type {
28672867
MEM_WRAP_CHECK_(n,t) \
28682868
perl_assert_ptr(d), \
28692869
perl_assert_ptr(s), \
2870+
assert_( \
2871+
PTR2UV((char *)(d) + (n) * sizeof (t)) <= PTR2UV((const char *)(s)) \
2872+
|| \
2873+
PTR2UV((const char *)(s) + (n) * sizeof (t)) <= PTR2UV((char *)(d)) \
2874+
) \
28702875
memcpy((char*)(d),(const char*)(s), (n) * sizeof(t)) \
28712876
)
28722877
#define ZeroD(d,n,t) \

0 commit comments

Comments
 (0)