OSDN Git Service

reimplement strverscmp to fix corner cases
authorRich Felker <dalias@aerifal.cx>
Tue, 23 Jun 2015 00:12:25 +0000 (00:12 +0000)
committerRich Felker <dalias@aerifal.cx>
Tue, 23 Jun 2015 00:29:57 +0000 (00:29 +0000)
commita59341420fdedb288d9ff80e73609ae44e9cf258
tree558bcbc501cbe1be079db3c8cc4aa7383200a703
parent153e952e1a688859d7095345b17e6c1df74a295c
reimplement strverscmp to fix corner cases

this interface is non-standardized and is a GNU invention, and as
such, our implementation should match the behavior of the GNU
function. one peculiarity the old implementation got wrong was the
handling of all-zero digit sequences: they are supposed to compare
greater than digit sequences of which they are a proper prefix, as in
009 < 00.

in addition, high bytes were treated with char signedness rather than
as unsigned. this was wrong regardless of what the GNU function does
since the resulting order relation varied by arch.

the new strverscmp implementation makes explicit the cases where the
order differs from what strcmp would produce, of which there are only
two.
src/string/strverscmp.c