public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* memcmp() doesn't
@ 2002-02-13  3:51 Georg Nikodym
  2002-02-14 14:39 ` [PATCH] memcmp() kernel janitor (was: memcmp() doesn't) Georg Nikodym
  0 siblings, 1 reply; 2+ messages in thread
From: Georg Nikodym @ 2002-02-13  3:51 UTC (permalink / raw)
  To: Linux Kernel List; +Cc: Linux ARM Kernel List

User's of X86 won't care but the generic memcmp() routine in
lib/string.c is incorrect...

The code reads:

/**
 * memcmp - Compare two areas of memory
 * @cs: One area of memory
 * @ct: Another area of memory
 * @count: The size of the area.
 */
int memcmp(const void * cs,const void * ct,size_t count)
{
	const unsigned char *su1, *su2;
	signed char res = 0;

	for( su1 = cs, su2 = ct; 0 < count; ++su1, ++su2, count--)
		if ((res = *su1 - *su2) != 0)
			break;
	return res;
}

Trouble is that the variable res is not big enough to hold all possible
results of a subtraction of two unsigned char quantities.

Changing res to int fixes things (and in the case of ARM, makes the
function smaller).

I can supply patches in BK or regular form but I suspect it'd be easier
for somebody "in the club" to simply make this change themselves.

-g


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2002-02-14 14:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-02-13  3:51 memcmp() doesn't Georg Nikodym
2002-02-14 14:39 ` [PATCH] memcmp() kernel janitor (was: memcmp() doesn't) Georg Nikodym

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox