Commit 964b03f
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
1 file changed
+0
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2867 | 2867 | | |
2868 | 2868 | | |
2869 | 2869 | | |
2870 | | - | |
2871 | | - | |
2872 | | - | |
2873 | | - | |
2874 | | - | |
2875 | 2870 | | |
2876 | 2871 | | |
2877 | 2872 | | |
| |||
0 commit comments