From: Julian Seward Date: Sun, 28 Jan 2007 06:32:01 +0000 (+0000) Subject: __stpcpy_chk: sync with Dirk's original proposal, and show origins X-Git-Tag: svn/VALGRIND_3_3_0~403 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5c1eb23d61bdc9e80eca256c7771762605dfb4cf;p=thirdparty%2Fvalgrind.git __stpcpy_chk: sync with Dirk's original proposal, and show origins git-svn-id: svn://svn.valgrind.org/valgrind/trunk@6556 --- diff --git a/memcheck/mc_replace_strmem.c b/memcheck/mc_replace_strmem.c index 6195b563fc..efd64687cd 100644 --- a/memcheck/mc_replace_strmem.c +++ b/memcheck/mc_replace_strmem.c @@ -542,7 +542,8 @@ GLIBC232_STRCHRNUL(m_libc_soname, strchrnul) GLIBC232_RAWMEMCHR(m_libc_soname, rawmemchr) -/* glibc variant of strcpy that checks the dest is big enough. */ +/* glibc variant of strcpy that checks the dest is big enough. + Copied from glibc-2.5/debug/test-strcpy_chk.c. */ #define GLIBC25___STRCPY_CHK(soname,fnname) \ char* VG_REPLACE_FUNCTION_ZU(soname,fnname) \ (char* dst, const char* src, SizeT len); \ @@ -568,7 +569,8 @@ GLIBC232_RAWMEMCHR(m_libc_soname, rawmemchr) GLIBC25___STRCPY_CHK(m_libc_soname, __strcpy_chk) -/* glibc variant of stpcpy that checks the dest is big enough. */ +/* glibc variant of stpcpy that checks the dest is big enough. + Copied from glibc-2.5/debug/test-stpcpy_chk.c. */ #define GLIBC25___STPCPY_CHK(soname,fnname) \ char* VG_REPLACE_FUNCTION_ZU(soname,fnname) \ (char* dst, const char* src, SizeT len); \ @@ -576,11 +578,11 @@ GLIBC25___STRCPY_CHK(m_libc_soname, __strcpy_chk) (char* dst, const char* src, SizeT len) \ { \ extern void _exit(int status); \ - do { \ - if (len-- == 0) \ + if (! len) \ + goto badness; \ + while ((*dst++ = *src++) != '\0') \ + if (--len == 0) \ goto badness; \ - *dst++ = *src; \ - } while (*src++ != '\0'); \ return dst - 1; \ badness: \ VALGRIND_PRINTF_BACKTRACE( \