This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug string/20524] New: strverscmp is inconsistent


https://sourceware.org/bugzilla/show_bug.cgi?id=20524

            Bug ID: 20524
           Summary: strverscmp is inconsistent
           Product: glibc
           Version: unspecified
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: string
          Assignee: unassigned at sourceware dot org
          Reporter: peda at lysator dot liu.se
  Target Milestone: ---

Consider this program:

#define _GNU_SOURCE
#include <string.h>
#include <stdio.h>

int main(void)
{
        char *strs[] = {
                "foo-01",
                "foo-01#",
                "foo-01hash",
                "foo-010",
                "foo-010#",
                "foo-010hash",
        };
        int i, j;

        for (i = 0; i < 6; ++i) {
                for (j = i + 1; j < 6; ++j) {
                        if (strverscmp(strs[i], strs[j]) < 0)
                                continue;
                        char *tmp = strs[i];
                        strs[i] = strs[j];
                        strs[j] = tmp;
                }
                printf("%s\n", strs[i]);
        }
        return 0;
}

I expected the strings to be pre-sorted, but the output is:

foo-01
foo-01#
foo-010
foo-010#
foo-010hash
foo-01hash

which is pretty useless. I don't really have an opinion which of 01
and 010 should be considered less, but the above is complete crap.

Since 000 is less than 00, maybe 010 should also be less than 01? But
that contradicts the ordering given in [1] which was what I started with.

[1] http://man7.org/linux/man-pages/man3/strverscmp.3.html

-- 
You are receiving this mail because:
You are on the CC list for the bug.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]