Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp463349rwi; Thu, 13 Oct 2022 00:05:10 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6eF/P3ArAlavkZABsggHrJ2c+QDavCFD9vccpExXyIIxlODR1kyCASzDa/qpiQsn5uSt7+ X-Received: by 2002:a05:6402:50d1:b0:45a:fc:86f4 with SMTP id h17-20020a05640250d100b0045a00fc86f4mr31425475edb.344.1665644709856; Thu, 13 Oct 2022 00:05:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665644709; cv=none; d=google.com; s=arc-20160816; b=hxfMUlS2wobWvp2NzMyxteFAfgzH+gvA8JZsYqcr9K4FV4Q0pzPm1+wYxLYURhaiOu taakr9XN+Dqxq6WkKqM+IDiaX1uHKePdxK9agGGbpalQKOeMgJBsg/saQrExVekuppmR KlSWC6X72bZBhXwYWjqEeYmMuWgpEO0eAmsDpNmERce4tFrpyZbyASXhllNx29hr4jeF t7jvO/CCovwumBQmA/8S7SWb6tyulI1PZO98tMm5dY1PTF0zKExRfGI/G3zT6OAGxpFT c1XAMcSAmt0d1ieQ6Ila4nneHosNjHySAsKgtE05H6/bQliyn7HU3P98sDV1hwQ0a+Te Xryw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=Wa23iEVxq5pkt0jTkWkOs0r3IRK/gObJsbHDyPQg/kY=; b=fz4zXya+9jxxXXKCr0ZOd1+xhj5Sj14+Tr8+XC4GKkD2TMu+GxR0Mwb90PNgV81NcQ IYc1CqTk7lVjaplrQaJ6zik+8TbOxX3iDA28H4+8wGCd9N9AHxU4f6AtpDGrHU7lL6Gt bcdNYP6V4tCKBrLAagLuU0O+ltosnSOiEcFCtG/KxQ2nu8w9JkSF4wJjPZC/Yy2c6f94 0ahN0XRqEkonhB7VoZA9bGiWczwSAWuNpjmgIL2xXTur4iibTHMSKPNwAWI46InZj91V pJsY2RGrLpWjKefZAoEEKmaVuOahhcDPVEBar78ZbGs6OCahp467IUUR0Bd7uZbRMvoP +RqA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dm11-20020a05640222cb00b0045938208482si15857809edb.377.2022.10.13.00.04.41; Thu, 13 Oct 2022 00:05:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229691AbiJMG4R (ORCPT + 99 others); Thu, 13 Oct 2022 02:56:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229746AbiJMG4K (ORCPT ); Thu, 13 Oct 2022 02:56:10 -0400 Received: from 1wt.eu (wtarreau.pck.nerim.net [62.212.114.60]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 23A4111B2E9 for ; Wed, 12 Oct 2022 23:56:05 -0700 (PDT) Received: (from willy@localhost) by pcw.home.local (8.15.2/8.15.2/Submit) id 29D6u3sr016637; Thu, 13 Oct 2022 08:56:03 +0200 Date: Thu, 13 Oct 2022 08:56:03 +0200 From: Willy Tarreau To: Rasmus Villemoes Cc: linux-kernel@vger.kernel.org Subject: Re: [PATCH] tools/nolibc/string: fix memcmp() implementation Message-ID: <20221013065603.GB16609@1wt.eu> References: <20221010113606.2329457-1-linux@rasmusvillemoes.dk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221010113606.2329457-1-linux@rasmusvillemoes.dk> User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Rasmus, On Mon, Oct 10, 2022 at 01:36:06PM +0200, Rasmus Villemoes wrote: > The C standard says that memcmp() must treat the buffers as consisting > of "unsigned chars". If char happens to be unsigned, the casts are ok, > but then obviously the c1 variable can never contain a negative > value. And when char is signed, the casts are wrong, and there's still > a problem with using an 8-bit quantity to hold the difference, because > that can range from -255 to +255. > > For example, assuming char is signed, comparing two 1-byte buffers, > one containing 0x00 and another 0x80, the current implementation would > return -128 for both memcmp(a, b, 1) and memcmp(b, a, 1), whereas one > of those should of course return something positive. You're totally right of course, thank you for spotting this one! I'm queuing it now. Regards, Willy