From: Rich Felker <dalias@libc.org>
To: musl@lists.openwall.com
Cc: Karl Palsson <karlp@etactica.com>
Subject: Re: [PATCH] search: call user compare with "correct" order params
Date: Wed, 24 Feb 2016 12:41:26 -0500 [thread overview]
Message-ID: <20160224174126.GR9349@brightrain.aerifal.cx> (raw)
In-Reply-To: <1456315949-16347-1-git-send-email-karlp@tweak.net.au>
On Wed, Feb 24, 2016 at 12:12:29PM +0000, Karl Palsson wrote:
> From: Karl Palsson <karlp@remake.is>
>
> IEEE Std 1003.1, 2013 Edition only defines the two params to the
> user callback as, "The compar argument points to a comparison function
> which the application shall supply (for example, strcmp()). It is called
> with two arguments that point to the elements being compared."
>
> Both uclibc and glibc provide the arguments as, "
> The comparison function referenced by compar is expected to have two
> arguments which point to the key object and to an array member, in that order
> "
>
> Musl currently provides the arguments as array member, then key object.
> While this is strictly compliant with the standard, it's equally
> compliant to have the parameters in the other order. If you are using
> lfind to search a list of complex structures where the key is not the
> same type as each entry, having these parameters arrive in unexpectd
> order can/will result in segfaults.
>
> => Swap the order of the arguments to the user function, maintaining
> equal compatibility with the standard, and gaining compatibility with
> uclibc and glibc.
I've read some of the scrollback from the discussion of this on IRC,
and I think:
1. Regardless of whether the patch is accepted or not, applications
using this interface in non-portable ways should be fixed.
2. As you said, lfind/lsearch are useless functions. Aside from the
order of the arguments being unspecified (which doesn't hurt code
using them in the intended way), they're just going to be a lot
slower than inlining the comparison in your own for loop.
Is there existing software that's affected by this issue for which
it's hard to get a fix upstream?
Rich
next prev parent reply other threads:[~2016-02-24 17:41 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-24 12:12 Karl Palsson
2016-02-24 17:41 ` Rich Felker [this message]
2016-03-08 11:43 ` Karl Pálsson
2016-03-08 17:24 ` dalias
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=20160224174126.GR9349@brightrain.aerifal.cx \
--to=dalias@libc.org \
--cc=karlp@etactica.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).