All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Georg Nikodym" <georgn@somanetworks.com>
To: Linux Kernel List <linux-kernel@vger.kernel.org>
Cc: Linux ARM Kernel List <linux-arm-kernel@lists.arm.linux.org.uk>
Subject: memcmp() doesn't
Date: 12 Feb 2002 22:51:26 -0500	[thread overview]
Message-ID: <1013572286.1581.95.camel@keller> (raw)

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


             reply	other threads:[~2002-02-13  3:52 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-02-13  3:51 Georg Nikodym [this message]
2002-02-14 14:39 ` [PATCH] memcmp() kernel janitor (was: memcmp() doesn't) Georg Nikodym

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1013572286.1581.95.camel@keller \
    --to=georgn@somanetworks.com \
    --cc=linux-arm-kernel@lists.arm.linux.org.uk \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.