From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934453AbcLTKBB (ORCPT ); Tue, 20 Dec 2016 05:01:01 -0500 Received: from ud10.udmedia.de ([194.117.254.50]:54970 "EHLO mail.ud10.udmedia.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753415AbcLTKBA (ORCPT ); Tue, 20 Dec 2016 05:01:00 -0500 Date: Tue, 20 Dec 2016 11:00:56 +0100 From: Markus Trippelsdorf To: "H. Peter Anvin" Cc: tglx@linutronix.de, linux-kernel@vger.kernel.org, mingo@kernel.org, linux-tip-commits@vger.kernel.org Subject: Re: [tip:x86/urgent] x86/tools: Fix gcc-7 warning in relocs.c Message-ID: <20161220100056.GA289@x4> References: <20161215124513.GA289@x4> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2016.12.20 at 01:30 -0800, H. Peter Anvin wrote: > I'd strongly prefer a non-data-dependent solution, specifically adding > at the top of sort_relocs(): > > if (!r->count) > return; > > However, by my reading of the C and POSIX standards, this is a gcc > error: qsort() should do nothing if the count is zero. No, it is invoking undefined behavior. Notice the nonnull attribute in /usr/include/stdlib.h: 739 /* Sort NMEMB elements of BASE, of SIZE bytes each, 740 using COMPAR to perform the comparisons. */ 741 extern void qsort (void *__base, size_t __nmemb, size_t __size, 742 __compar_fn_t __compar) __nonnull ((1, 4)); But feel free to revert my patch and add your solution. -- Markus