Mail Archives: djgpp-workers/1998/03/18/07:41:46
On Tue, Mar 17, 1998 at 12:53:21PM +0000, Burton Radons wrote:
> memcmp used to compare using char-by-char, so I replaced it with
> int-by-int -- quick optimizations, but it hadn't been done in three
> years, so... bcmp follows this message.
[...]
Be careful with these kind of optimalizations! This version can produce
SIGSEGV in some special cases where memcmp works. Here is how: assume
that one of the pointers (say p1) looks like this: (p1 & 0xfff) = 0xffd.
And assume that the address (p1+3) is not valid (this address is in the
next page, which is not valid). If you try to call your version with
memcmp (p1,p2,5) it will give you a SIGSEGV. However the original memcmp()
can work depending on your data. So the two versions are not equivalent.
bye, Laszlo
- Raw text -