mailing list of musl libc
 help / color / mirror / code / Atom feed
* [PATCH] fix lsearch and lfind to pass key as first arg to the compar callback
@ 2017-03-05 22:03 Szabolcs Nagy
  2017-03-06  1:05 ` Rich Felker
  0 siblings, 1 reply; 2+ messages in thread
From: Szabolcs Nagy @ 2017-03-05 22:03 UTC (permalink / raw)
  To: musl

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



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] fix lsearch and lfind to pass key as first arg to the compar callback
  2017-03-05 22:03 [PATCH] fix lsearch and lfind to pass key as first arg to the compar callback Szabolcs Nagy
@ 2017-03-06  1:05 ` Rich Felker
  0 siblings, 0 replies; 2+ messages in thread
From: Rich Felker @ 2017-03-06  1:05 UTC (permalink / raw)
  To: musl

On Sun, Mar 05, 2017 at 11:03:35PM +0100, Szabolcs Nagy wrote:
> 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.

Thanks. Committed and pushed.

Rich


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-03-06  1:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-05 22:03 [PATCH] fix lsearch and lfind to pass key as first arg to the compar callback Szabolcs Nagy
2017-03-06  1:05 ` Rich Felker

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).