From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/9379 Path: news.gmane.org!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: [PATCH] search: call user compare with "correct" order params Date: Wed, 24 Feb 2016 12:41:26 -0500 Message-ID: <20160224174126.GR9349@brightrain.aerifal.cx> References: <1456315949-16347-1-git-send-email-karlp@tweak.net.au> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1456335705 4356 80.91.229.3 (24 Feb 2016 17:41:45 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 24 Feb 2016 17:41:45 +0000 (UTC) Cc: Karl Palsson To: musl@lists.openwall.com Original-X-From: musl-return-9392-gllmg-musl=m.gmane.org@lists.openwall.com Wed Feb 24 18:41:44 2016 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1aYdRX-0000On-QS for gllmg-musl@m.gmane.org; Wed, 24 Feb 2016 18:41:43 +0100 Original-Received: (qmail 26622 invoked by uid 550); 24 Feb 2016 17:41:41 -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 26602 invoked from network); 24 Feb 2016 17:41:40 -0000 Content-Disposition: inline In-Reply-To: <1456315949-16347-1-git-send-email-karlp@tweak.net.au> User-Agent: Mutt/1.5.21 (2010-09-15) Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:9379 Archived-At: On Wed, Feb 24, 2016 at 12:12:29PM +0000, Karl Palsson wrote: > From: Karl Palsson > > 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