diff options
author | ph10 <ph10@2f5784b3-3f2a-0410-8824-cb99058d5e15> | 2007-03-09 16:17:46 +0000 |
---|---|---|
committer | ph10 <ph10@2f5784b3-3f2a-0410-8824-cb99058d5e15> | 2007-03-09 16:17:46 +0000 |
commit | 35de372fe66e92c74f0b81b1dce1cd8aac45e4f4 (patch) | |
tree | 07f388984ce129bd9d9f7c185a4ace54ff5d841d | |
parent | 937dd03bc0c7193b21a1f8139f8c5ade875ae5c1 (diff) | |
download | pcre-35de372fe66e92c74f0b81b1dce1cd8aac45e4f4.tar.gz |
Fix bug in emulated memmove() for downward moves.
git-svn-id: svn://vcs.exim.org/pcre/code/trunk@118 2f5784b3-3f2a-0410-8824-cb99058d5e15
-rw-r--r-- | ChangeLog | 15 | ||||
-rw-r--r-- | pcre_internal.h | 20 |
2 files changed, 24 insertions, 11 deletions
@@ -60,9 +60,16 @@ Version 7.1 05-Mar-07 called when UTF-8 support is disabled. Otherwise there are problems with a shared library. -10. The emulated memmove() function in pcre_internal.h (provided for those - environments that have neither memmove() nor bcopy()) was defining its - arguments as char * instead of void *. +10. Fixed two bugs in the emulated memmove() function in pcre_internal.h: + + (a) It was defining its arguments as char * instead of void *. + + (b) It was assuming that all moves were upwards in memory; this was true + a long time ago when I wrote it, but is no longer the case. + + The emulated memove() is provided for those environments that have neither + memmove() nor bcopy(). I didn't think anyone used it these days, but that + is clearly not the case, as these two bugs were recently reported. 11. The script PrepareRelease is now distributed: it calls 132html, CleanTxt, and Detrail to create the HTML documentation, the .txt form of the man @@ -105,7 +112,7 @@ Version 7.1 05-Mar-07 I have added a new /Z option to pcretest that replaces the length and offset values with spaces. This is now used to make test 3 independent of link size. - + Version 7.0 19-Dec-06 --------------------- diff --git a/pcre_internal.h b/pcre_internal.h index d0956af..9caec72 100644 --- a/pcre_internal.h +++ b/pcre_internal.h @@ -200,9 +200,7 @@ option on the command line. */ /* To cope with SunOS4 and other systems that lack memmove() but have bcopy(), define a macro for memmove() if HAVE_MEMMOVE is false, provided that HAVE_BCOPY is set. Otherwise, include an emulating function for those systems that have -neither (there some non-Unix environments where this is the case). This assumes -that all calls to memmove are moving strings upwards in store, which is the -case in PCRE. */ +neither (there some non-Unix environments where this is the case). */ #if ! HAVE_MEMMOVE #undef memmove /* some systems may have a macro */ @@ -215,10 +213,18 @@ pcre_memmove(void *d, const void *s, size_t n) size_t i; unsigned char *dest = (unsigned char *)d; const unsigned char *src = (const unsigned char *)s; -dest += n; -src += n; -for (i = 0; i < n; ++i) *(--dest) = *(--src); -return (void *)dest; +if (dest > src) + { + dest += n; + src += n; + for (i = 0; i < n; ++i) *(--dest) = *(--src); + return (void *)dest; + } +else + { + for (i = 0; i < n; ++i) *dest++ = *src++; + return (void *)(dest - n); + } } #define memmove(a, b, c) pcre_memmove(a, b, c) #endif /* not HAVE_BCOPY */ |