[compiler-rt] [compiler-rt][memprof] memccpy interception (PR #155101)

Teresa Johnson via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 25 14:35:05 PDT 2025


================
@@ -49,6 +49,16 @@ int internal_memcmp(const void* s1, const void* s2, uptr n) {
   return 0;
 }
 
+void *internal_memccpy(void *dest, const void *src, int c, uptr n) {
+  char *d = (char *)dest;
+  const char *s = (const char *)src;
+  uptr i = 0;
+  for (; i < n && s[i] != c; ++i) d[i] = s[i];
+  if (n > 0 && i < n - 1)
----------------
teresajohnson wrote:

I think the second part of this check should be "i < n" ? I.e. if c was found as the nth character, I believe that i=n-1 after the above loop and it should return non-nullptr. In this case d+i+1 = d+n-1+1 = d+n, which seems correct.

https://github.com/llvm/llvm-project/pull/155101


More information about the llvm-commits mailing list