From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by sourceware.org (Postfix) with ESMTPS id CA9AF3858D33 for ; Mon, 20 Nov 2023 19:05:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CA9AF3858D33 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org CA9AF3858D33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::42f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700507136; cv=none; b=qNqrjeKCtUs/JDzipRG2MHF1qtNz5PSNOCTzky7bi2v3wYpLcLhrP4SlDeXLVhz8g/6oRZgpoSM6cSbx+9BY2x0STft9z+t/P8GJWeU7bNqISUADjPldCoPPxQY1DSQcEpw1Slc1KL5pbHV64eSJdbWI0jAr+5rLSQmau6OBWA0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700507136; c=relaxed/simple; bh=AeQUbjSqCkPv/DY7H4MFYL/cRARh2FPB5fXTpr4gbb8=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=xEfSqZR+b/G590F3RdnlpYypaFu3mqiiVYBQ2T5Uqtx00PSxig1UVoWzIXL9En7M2Bn76NbaEDBpNL5emgvzdzfbaXkt4AqmKOGRinw7ujDxEh/hvFn92iUHalKFbNhuepQPi8eYQdOxCvKELp8FgWw/GDMrA2ghb5r5sAGk3v0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-6cb7951d713so1116736b3a.1 for ; Mon, 20 Nov 2023 11:05:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1700507134; x=1701111934; darn=sourceware.org; h=content-transfer-encoding:in-reply-to:organization:from:references :to:content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=63iPmOA7jOs8xTbTqRqYazf9kML8fNPuEoz3+CpL2wE=; b=w7VCDUZVF0Mk4m6X6pP3jV1IUCS6SrjKVvf6F8MXM/OS3mxealjkl+/Zj3CwC5tPww UinENEAon1+iOh6UPC1v+NYJ7n+l7SjyA3yZ/puCIHwxS++U7xy+2F7dZtEGz9YERg2H b0oqfVkElXnm16fhvxeKtlugjNMzjrKqnlmB1Rc6RzaF4zdqT2xKfqbe2fDEegtpSIOi qQ1i3QfoPDfoZnFJaiIDbC40Qoah1I7lG1U9cdqrAYVI+nvuEfFUx4PIGySve2eJVn/v IoLiUN6Dko94syPO8XTTNKIDdijAzpebZvYxXqPXXY1kM072/BHCjr2hiO9x4KGYba5K s4AQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700507134; x=1701111934; h=content-transfer-encoding:in-reply-to:organization:from:references :to:content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=63iPmOA7jOs8xTbTqRqYazf9kML8fNPuEoz3+CpL2wE=; b=KowOFuDL/sfEF6UvhIX2Zs+m1gyyMiNIQQpuEBApkWVP1TOUIPzNPQxnNObJ8BPMSl B6Fes8O4H2LOCL+RTOVrbvPHljDpC2MFTQMvfuNuJ5x5VTd2R5K9Dg/fhmO9s/RnsxZ7 L1JZpj/gjhyWstXt3iRmMZ/DcSqEttHFUV3TXBZ70HqFmRZbIRD3dmyT9vtcQ6QgTSCL Io1BTXH3AJdxsksa4O+0K0QDXpVmdcErxdz+WnFfcIOfkJYmY9qfMv5BZeYSrTNsXONJ p4UTKR6ENpNWWHWpsIL2x2arKtwVVJd1/s3vVfiSZl7UwNmQmVYS1TaGTfstSRzzvu+m ZxLQ== X-Gm-Message-State: AOJu0YwNwZW/mH+YpE/45XtF2i9kWwz5Fn7uzHHR1fF+DpTwhkxEIY7q aaeJL0CGJs5O6FwXjT6s0ysdGTfa9a/UAtP3uFveSQ== X-Google-Smtp-Source: AGHT+IFawjpTiNeq95cdJ9BQvpjqNiE2FCz2HRSyGptlmMcfXjHpIWeILZUOXAgpE55A74Q1hG47dw== X-Received: by 2002:a05:6a20:748b:b0:181:a38c:8106 with SMTP id p11-20020a056a20748b00b00181a38c8106mr572232pzd.20.1700507133768; Mon, 20 Nov 2023 11:05:33 -0800 (PST) Received: from ?IPV6:2804:1b3:a7c2:94e:b99b:7812:71a8:3bda? ([2804:1b3:a7c2:94e:b99b:7812:71a8:3bda]) by smtp.gmail.com with ESMTPSA id fi2-20020a056a00398200b006cb7e61cfa7sm3056337pfb.36.2023.11.20.11.05.32 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 20 Nov 2023 11:05:33 -0800 (PST) Message-ID: <5989a88e-500f-4524-aaa0-c3f77aba0e5c@linaro.org> Date: Mon, 20 Nov 2023 16:05:30 -0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/3] stdlib: Avoid another self-comparison in qsort Content-Language: en-US To: Florian Weimer , libc-alpha@sourceware.org References: <58229f369d7bb3eb1883de9ba0ff2ad974853c5b.1700246487.git.fweimer@redhat.com> From: Adhemerval Zanella Netto Organization: Linaro In-Reply-To: <58229f369d7bb3eb1883de9ba0ff2ad974853c5b.1700246487.git.fweimer@redhat.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 17/11/23 15:44, Florian Weimer wrote: > In the insertion phase, we could run off the start of the array if the > comparison function never runs zero. In that case, it never finds the > initial element that terminates the iteration. LGTM, thanks. Reviewed-by: Adhemerval Zanella > --- > stdlib/qsort.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/stdlib/qsort.c b/stdlib/qsort.c > index ad110e8a89..6d0c4447ec 100644 > --- a/stdlib/qsort.c > +++ b/stdlib/qsort.c > @@ -217,7 +217,7 @@ insertion_sort_qsort_partitions (void *const pbase, size_t total_elems, > while ((run_ptr += size) <= end_ptr) > { > tmp_ptr = run_ptr - size; > - while (cmp (run_ptr, tmp_ptr, arg) < 0) > + while (run_ptr != tmp_ptr && cmp (run_ptr, tmp_ptr, arg) < 0) > tmp_ptr -= size; > > tmp_ptr += size;