avr-libc-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-libc-dev] [ Bug #1720 ] memcmp bug ?


From: Theodore A. Roth
Subject: Re: [avr-libc-dev] [ Bug #1720 ] memcmp bug ?
Date: Mon, 18 Nov 2002 14:57:23 -0800 (PST)

On Mon, 18 Nov 2002, Joerg Wunsch wrote:

:) As Theodore A. Roth wrote:
:)
:) >   http://savannah.nongnu.org/bugs/?func=detailbug&bug_id=1720&group_id=2140
:) >
:) > Is this really a bug?
:)
:) Yes, it is:
:)
:) ``7.21.4 Comparison functions
:)
:) The sign of a nonzero value returned by the comparison functions memcmp,
:) strcmp, and strncmp is determined by the sign of the difference between
:) the values of the first pair of characters (both interpreted as unsigned
:) char) that differ in the objects being compared.''

I'm pretty sure this is exactly what the existing code is doing. (see
Marek's post and my reply)

:)
:) > If the change should be made, I think it would be the following patch
:) > (don't sign extend the result). Is this patch correct?
:)
:) >  .memcmp_done:
:) > -; ret_hi = SREG.C ? 0xFF : 0
:) > -       sbc     ret_hi, ret_hi
:) >         ret
:)
:) Not yet.  It needs a clr ret_hi, since the upper byte must be made
:) 0.

Well, I think we're both trying to reach the same (incorrect) result. I
agree I should have done done something with ret_hi, but not zero it.
Setting ret_hi would always make the return value >= 0. You need to have
bit 7 (MSB) of ret_hi set for a < 0 result.

My original patch is wrong and discussion of it should be dropped. :-)

The bug submitter didn't give enough code to reproduce the "bug" so we
don't really know if they had a mistake in their code or not. Alas, they
also didn't leave an email address, so I can't follow up on it with them.
(I've just changed the bug submission form to include email address as a
required field).

Ted Roth





reply via email to

[Prev in Thread] Current Thread [Next in Thread]