Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20121205191819.e83c8c3c.idunham@lavabit.com>
Date: Wed, 5 Dec 2012 19:18:19 -0800
From: Isaac Dunham <idunham@...abit.com>
To: musl@...ts.openwall.com
Subject: Re: Fix strverscmp

On Wed, 5 Dec 2012 21:26:40 -0500
Rich Felker <dalias@...ifal.cx> wrote:

> > I'm getting the idea that that may actually work...in which case my
> > last version is unneeded.
> > Except, it breaks here:
> > 00123
> > 001145 <-should be the lesser (the leading zeros)
> 
> Yes, I was unaware of the leading-zero semantics when I wrote that.
> See my revised email with a proposed algorithm.

Which is almost exactly the same as the method below:

> > OTOH, it could be done by recording the zero while walking up the chain:
> > /*NOT tested*/
> > while (*l && *r && l[0]==r[0]){
> > 	if (l[0]='0'){
> > 		nozero=1;
> 
> It can't set the flag unconditionally, only if the previous byte was
> not a digit. Otherwise, non-leading zeros would break handling of
> numeric differences.
Fortunately for us, that appears to be incorrect:
idunham@...acal:~$ ./a.out jan012 jan0111
1
1
idunham@...acal:~$ ./a.out jan0001 jan001
-1
-1
idunham@...acal:~$ ./a.out 0001 001
-1
-1
idunham@...acal:~$ ./a.out 001 0001
1
1
idunham@...acal:~$ ./a.out 0012 00111
1
1
idunham@...acal:~$ ./a.out 00012 00111
-1
-1
idunham@...acal:~$ ./a.out 00120 00111
1
1

That's testing with the attached version.


-- 
Isaac Dunham <idunham@...abit.com>

View attachment "strvers.c" of type "text/x-csrc" (793 bytes)

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.