delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1998/03/18/07:41:46

Date: Wed, 18 Mar 1998 13:35:27 +0100 (MET)
From: MOLNAR Laszlo <s0052mol AT hszk DOT bme DOT hu>
To: djgpp-workers AT delorie DOT com
Subject: Re: libc replacement (memcmp)
Message-ID: <Pine.GSO.3.96.980318133415.12980A-100000@ural2>
MIME-Version: 1.0

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019