mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Isaac Dunham <idunham@lavabit.com>
To: musl@lists.openwall.com
Subject: [PATCH] Fix strverscmp
Date: Wed, 5 Dec 2012 11:09:59 -0800	[thread overview]
Message-ID: <20121205110959.87b6111a.idunham@lavabit.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 325 bytes --]

On the Puppy Linux forums, technosaurus mentioned that musl's strverscmp implementation was broken; he has a small version of strverscmp that works properly, which he placed under a CC0-like license.

This patch changes strverscmp to use his version.  Results are comparable to glibc.

-- 
Isaac Dunham <idunham@lavabit.com>

[-- Attachment #2: strverscmp.diff --]
[-- Type: text/x-diff, Size: 1327 bytes --]

commit 21b9e883f440de900764a2e4077752268724c4db
Author: Isaac Dunham <idunham@lavabit.com>
Date:   Wed Dec 5 10:48:33 2012 -0800

    Fix strverscmp.
    
    The original version used strcmp, resulting in incorrect sorting order.
    This version, based on a version Brad Conroy (technosaurus) published,
    behaves similarly to the glibc version.

diff --git a/src/string/strverscmp.c b/src/string/strverscmp.c
index 7054967..bab3e64 100644
--- a/src/string/strverscmp.c
+++ b/src/string/strverscmp.c
@@ -1,7 +1,27 @@
+/*
+ * Based on an implementation by Brad Conroy (technosaurus) 
+ * published on the Puppy Linux forums.
+ *
+ * This work is released to the Public Domain.
+ * In locales that do not recognize public domain it is:
+ * Copyright Brad Conroy 2012, permission is hereby granted to use this work in
+ * accordance with any license approved by the Open Source Initiative for any 
+ * purpose without restriction in perpetuity.
+ */
 #include <string.h>
 
 int strverscmp(const char *l, const char *r)
 {
-	/* FIXME */
-	return strcmp(l, r);
+	int ret=0, buf=0;
+	while ( *l && *r && l[0]==r[0] ) {
+		l++;
+		r++;
+	}
+	do {
+		ret=(10 * ret) + l++[0] - '0'; 
+	} while ( '0' <= l[0] && l[0] <= '9') ;
+	do {
+		buf=(10 * buf) + r++[0] - '0'; 
+	} while ( '0' <= r[0] && r[0] <= '9');
+	return ret - buf;
 }

             reply	other threads:[~2012-12-05 19:09 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-05 19:09 Isaac Dunham [this message]
2012-12-05 19:35 ` Rich Felker
2012-12-06  0:43   ` Isaac Dunham
2012-12-06  1:00     ` Rich Felker
2012-12-06  2:14       ` Rich Felker
2012-12-06  2:21       ` Isaac Dunham
2012-12-06  2:26         ` Rich Felker
2012-12-06  3:18           ` Isaac Dunham
2012-12-06  4:14             ` Rich Felker
2012-12-07  0:36               ` Isaac Dunham

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=20121205110959.87b6111a.idunham@lavabit.com \
    --to=idunham@lavabit.com \
    --cc=musl@lists.openwall.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).