public inbox for newlib-cvs@sourceware.org
help / color / mirror / Atom feed
From: Corinna Vinschen <corinna@sourceware.org>
To: newlib-cvs@sourceware.org
Subject: [newlib-cygwin/main] fix strverscmp comparison of digit sequence with non-digits
Date: Mon,  8 Jan 2024 16:01:51 +0000 (GMT)	[thread overview]
Message-ID: <20240108160151.77D9A3858D35@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=9a863f713af24a3b18c165c640c936a4c0b707ea

commit 9a863f713af24a3b18c165c640c936a4c0b707ea
Author:     Brian Inglis <Brian.Inglis@SystematicSW.ab.ca>
AuthorDate: Mon Jan 8 06:56:21 2024 -0700
Commit:     Corinna Vinschen <corinna@vinschen.de>
CommitDate: Mon Jan 8 17:01:25 2024 +0100

    fix strverscmp comparison of digit sequence with non-digits
    
    From: Rich Felker <dalias@aerifal.cx>
    Date: Mon, 7 Nov 2022 22:17:55 -0500
    
    the rule that longest digit sequence not beginning with a zero is
    greater only applies when both sequences being compared are
    non-degenerate. this is spelled out explicitly in the man page, which
    may be deemed authoritative for this nonstandard function: "If one or
    both of these is empty, then return what strcmp(3) would have
    returned..."
    
    we were wrongly treating any sequence of digits not beginning with a
    zero as greater than a non-digit in the other string.
    
    Signed-off-by: Brian Inglis <Brian.Inglis@SystematicSW.ab.ca>

Diff:
---
 newlib/libc/string/strverscmp.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/newlib/libc/string/strverscmp.c b/newlib/libc/string/strverscmp.c
index 04aa7213ad98..0117421c9e93 100644
--- a/newlib/libc/string/strverscmp.c
+++ b/newlib/libc/string/strverscmp.c
@@ -76,9 +76,9 @@ int strverscmp(const char *l0, const char *r0)
 		else if (c!='0') z=0;
 	}
 
-	if (l[dp]!='0' && r[dp]!='0') {
-		/* If we're not looking at a digit sequence that began
-		 * with a zero, longest digit string is greater. */
+	if (l[dp]-'1'<9U && r[dp]-'1'<9U) {
+		/* If we're looking at non-degenerate digit sequences starting
+		 * with nonzero digits, longest digit string is greater. */
 		for (j=i; isdigit(l[j]); j++)
 			if (!isdigit(r[j])) return 1;
 		if (isdigit(r[j])) return -1;

                 reply	other threads:[~2024-01-08 16:01 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20240108160151.77D9A3858D35@sourceware.org \
    --to=corinna@sourceware.org \
    --cc=newlib-cvs@sourceware.org \
    /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.
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 read-only IMAP folder(s) and NNTP newsgroup(s).