Skip to content

Commit 964b03f

Browse files
committed
Revert "assert under DEBUGGING that Copy's arguments don't overlap"
This reverts commit 0045848. This check was intended to prevent undefined behavior in case memcpy's source/destination objects overlap. Unfortunately, the check itself causes compiler warnings if one of the arguments is a string literal: regexec.c:4810:25: warning: result of comparison against a string literal is unspecified (use an explicit string comparison function instead) [-Wstring-compare] Copy("fi", mod_pat, pat_len, U8); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ./handy.h:2871:52: note: expanded from macro 'CopyD' PTR2UV((char *)(d) + (n) * sizeof (t)) <= PTR2UV((const char *)(s)) \ Indeed, Copy("foo", d, n) could trip the assert even if no overlap is possible: Each instance of s in the macro body expands to a separate copy of "foo". Compilers are not required to coalesce string literals (i.e. allocate only a single copy of each distinct string), so the two comparisons could be looking at different objects. It is at least theoretically possible that the compiler places one copy of "foo" before d in memory and the other "foo" after d, such that neither condition holds. We could work around the problem if we had a compile-time "is this token sequence a string literal?" check, but I'm not aware of such a thing. So instead of adding more complexity, just take the check out again.
1 parent beb2f63 commit 964b03f

File tree

1 file changed

+0
-5
lines changed

1 file changed

+0
-5
lines changed

handy.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2867,11 +2867,6 @@ 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-
) \
28752870
memcpy((char*)(d),(const char*)(s), (n) * sizeof(t)) \
28762871
)
28772872
#define ZeroD(d,n,t) \

0 commit comments

Comments
 (0)