Skip to content

Commit 20b41c0

Browse files
Provide a replacement for mempcpy.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@6469
1 parent 6f9073a commit 20b41c0

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

memcheck/mc_replace_strmem.c

+36
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,42 @@ GLIBC232_RAWMEMCHR(m_libc_soname, rawmemchr)
558558
GLIBC25___STRCPY_CHK(m_libc_soname, __strcpy_chk)
559559

560560

561+
/* mempcpy */
562+
#define GLIBC25_MEMPCPY(soname, fnname) \
563+
void* VG_REPLACE_FUNCTION_ZU(soname,fnname) \
564+
( void *dst, const void *src, SizeT len ); \
565+
void* VG_REPLACE_FUNCTION_ZU(soname,fnname) \
566+
( void *dst, const void *src, SizeT len ) \
567+
{ \
568+
register char *d; \
569+
register char *s; \
570+
SizeT len_saved = len; \
571+
\
572+
if (len == 0) \
573+
return dst; \
574+
\
575+
if (is_overlap(dst, src, len, len)) \
576+
RECORD_OVERLAP_ERROR("mempcpy", dst, src, len); \
577+
\
578+
if ( dst > src ) { \
579+
d = (char *)dst + len - 1; \
580+
s = (char *)src + len - 1; \
581+
while ( len-- ) { \
582+
*d-- = *s--; \
583+
} \
584+
} else if ( dst < src ) { \
585+
d = (char *)dst; \
586+
s = (char *)src; \
587+
while ( len-- ) { \
588+
*d++ = *s++; \
589+
} \
590+
} \
591+
return (void*)( ((char*)dst) + len_saved ); \
592+
}
593+
594+
GLIBC25_MEMPCPY(m_libc_soname, mempcpy)
595+
596+
561597
/*------------------------------------------------------------*/
562598
/*--- AIX stuff only after this point ---*/
563599
/*------------------------------------------------------------*/

0 commit comments

Comments
 (0)