From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2155) id 77D9A3858D35; Mon, 8 Jan 2024 16:01:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 77D9A3858D35 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1704729711; bh=7s6vBuaJ9LD+zEr3QUKrP2nDhW17LAWvHqP6P9IlWmc=; h=From:To:Subject:Date:From; b=fW5b7g6HIsA9/qdAWxt7OfuzFM9soqYOmqh7q3qKvZFnveRgGnMPuSrfPGysZdoke TqTRa+WZDjKxATvQ7E06OPGlOquTarQjGPlf8qsJJrevtNAHAF45lWEmcOC8Hosca2 ZA8O+vPwLc5xqUcaFw/i+NYwKP90ryFH2L+j4XxA= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Corinna Vinschen To: newlib-cvs@sourceware.org Subject: [newlib-cygwin/main] fix strverscmp comparison of digit sequence with non-digits X-Act-Checkin: newlib-cygwin X-Git-Author: Brian Inglis X-Git-Refname: refs/heads/main X-Git-Oldrev: 573458e7fc4f5247874b139a17e7e54827c92440 X-Git-Newrev: 9a863f713af24a3b18c165c640c936a4c0b707ea Message-Id: <20240108160151.77D9A3858D35@sourceware.org> Date: Mon, 8 Jan 2024 16:01:51 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3D9a863f713af= 24a3b18c165c640c936a4c0b707ea commit 9a863f713af24a3b18c165c640c936a4c0b707ea Author: Brian Inglis AuthorDate: Mon Jan 8 06:56:21 2024 -0700 Commit: Corinna Vinschen CommitDate: Mon Jan 8 17:01:25 2024 +0100 fix strverscmp comparison of digit sequence with non-digits =20 From: Rich Felker Date: Mon, 7 Nov 2022 22:17:55 -0500 =20 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..." =20 we were wrongly treating any sequence of digits not beginning with a zero as greater than a non-digit in the other string. =20 Signed-off-by: Brian Inglis 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/strverscm= p.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!=3D'0') z=3D0; } =20 - if (l[dp]!=3D'0' && r[dp]!=3D'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=3Di; isdigit(l[j]); j++) if (!isdigit(r[j])) return 1; if (isdigit(r[j])) return -1;