From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/11104 Path: news.gmane.org!.POSTED!not-for-mail From: Szabolcs Nagy Newsgroups: gmane.linux.lib.musl.general Subject: [PATCH] fix lsearch and lfind to pass key as first arg to the compar callback Date: Sun, 5 Mar 2017 23:03:35 +0100 Message-ID: <20170305220334.GH2082@port70.net> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1488751442 2611 195.159.176.226 (5 Mar 2017 22:04:02 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 5 Mar 2017 22:04:02 +0000 (UTC) User-Agent: Mutt/1.6.0 (2016-04-01) To: musl@lists.openwall.com Original-X-From: musl-return-11119-gllmg-musl=m.gmane.org@lists.openwall.com Sun Mar 05 23:03:58 2017 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1ckeFv-000053-V6 for gllmg-musl@m.gmane.org; Sun, 05 Mar 2017 23:03:56 +0100 Original-Received: (qmail 29759 invoked by uid 550); 5 Mar 2017 22:03:59 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 29718 invoked from network); 5 Mar 2017 22:03:55 -0000 Mail-Followup-To: musl@lists.openwall.com Content-Disposition: inline Xref: news.gmane.org gmane.linux.lib.musl.general:11104 Archived-At: this is not a conformance issue as posix does not specify the argument order, but the order is specified for bsearch and some systems document the order for lsearch consistently (openbsd). since there were two indpendent reports of this issue it's better to use the more widely expected argument order. --- in both reported cases upstream got fixed, but i think it is worth changing anyway. src/search/lsearch.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/search/lsearch.c b/src/search/lsearch.c index 63f31922..5eb5cc2b 100644 --- a/src/search/lsearch.c +++ b/src/search/lsearch.c @@ -9,7 +9,7 @@ void *lsearch(const void *key, void *base, size_t *nelp, size_t width, size_t i; for (i = 0; i < n; i++) - if (compar(p[i], key) == 0) + if (compar(key, p[i]) == 0) return p[i]; *nelp = n+1; return memcpy(p[n], key, width); @@ -23,7 +23,7 @@ void *lfind(const void *key, const void *base, size_t *nelp, size_t i; for (i = 0; i < n; i++) - if (compar(p[i], key) == 0) + if (compar(key, p[i]) == 0) return p[i]; return 0; } -- 2.11.0