From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS22989 209.51.188.0/24 X-Spam-Status: No, score=-3.7 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS, SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 954A91F4B4 for ; Sun, 4 Apr 2021 06:43:27 +0000 (UTC) Received: from localhost ([::1]:44486 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lSwTm-0007YM-EA for normalperson@yhbt.net; Sun, 04 Apr 2021 02:43:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33444) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lSwTj-0007Y1-G2 for bug-gnulib@gnu.org; Sun, 04 Apr 2021 02:43:23 -0400 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]:36570) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lSwTh-0001bZ-QO for bug-gnulib@gnu.org; Sun, 04 Apr 2021 02:43:23 -0400 Received: by mail-pl1-x62c.google.com with SMTP id ay2so4281841plb.3 for ; Sat, 03 Apr 2021 23:43:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=oPNYFzEXvs4aNcoJj8jl42mZ+ZZmvARI1LIvpUFu3jE=; b=aYPz+hC3asVXT6KSFGGG4tNpKUpqwbd8En6YBfWKDTrupTibfA4v9xHRo/IgGvAS2L UP2JiDm0/BEYCEZCUsnhOxQzeUwCJkXPNLRX09DGejEC1tVLGTZxjABlH4GdqffEQyEE Pe8sCfRBFA4t+/xiDWh8OXa5csA/2RG2Q8ZWWsGAUWvocgaGDYMLtjcaEqlT0vJ0p6aZ C6d8tOaI4Eus8dcbaqn0VFSPAGV5wXHuN2bmsAbhlHQOtlQJIEyFpUh1dXIJ5ltFsaeU BhRYo5SPGPv+o/zpZ97MGvNY7M6YW5G6QkDzfycVq99WkmHBUNKbreFXGZQucWkaHNgd zjwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=oPNYFzEXvs4aNcoJj8jl42mZ+ZZmvARI1LIvpUFu3jE=; b=RRWsFLQRdzvmnVM6MOIEVrAPxZiUa/9af0itpVtoMwwQ6ZnxEP69o8HIdmTdNLah4f GyZX4CPYhO3DmvBAJEFCUAdnvyHAcMZi41ienXCv7/KsZqgCbFhdefJBXa+wY6DNDGcM 02eUM0inPhHw1A2Fv2R4oan9zBiVmWD+dKUpNdjRAxSMsmmRvgOjYXflGpR/7790c9yj pFj1aOyHqQmn7eqsyWCfRGkHbmW8qIMzjNSpyTT7p+4qb91ORhQYmM2rTIUC7eqvmtSK qGawEb5pt/yyVA7ASFXUW+ueNkMf8GuOX+OZUDAuA7Ppk8B2DSMMCHmaGkPNCyr3YduL k2og== X-Gm-Message-State: AOAM53386UokOzKPFX6xu70MEMsiTABc/ynEP/dd/l+Ncog1VkzI0iqu GK52xX+N6e6HjlVAdzQDYJdjFe70S3rmY6be4Vo= X-Google-Smtp-Source: ABdhPJxe3SJgF5amy74Pv0FrIIX9OLkcjsaO9+Bx3CcjoHsuOB5P+GkDHQgg5/K9FIOkYSa/Tg1qicw0he9PgGwsTvc= X-Received: by 2002:a17:902:c085:b029:e7:3266:6d4e with SMTP id j5-20020a170902c085b02900e732666d4emr8171350pld.54.1617518600328; Sat, 03 Apr 2021 23:43:20 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: =?UTF-8?Q?Marc_Nieper=2DWi=C3=9Fkirchen?= Date: Sun, 4 Apr 2021 08:43:08 +0200 Message-ID: Subject: Re: New function xpalloc in module xalloc To: noloader@gmail.com Content-Type: multipart/alternative; boundary="00000000000097189e05bf1fe559" Received-SPF: pass client-ip=2607:f8b0:4864:20::62c; envelope-from=marc.nieper@gmail.com; helo=mail-pl1-x62c.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, FREEMAIL_REPLY=1, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: bug-gnulib@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Gnulib discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?Q?Marc_Nieper=2DWi=C3=9Fkirchen?= , "bug-gnulib@gnu.org List" Errors-To: bug-gnulib-bounces+normalperson=yhbt.net@gnu.org Sender: "bug-gnulib" --00000000000097189e05bf1fe559 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable SIZE_MAX could be defined as -1 promoted to an unsigned type, meaning that the unsigned comparison would always yield false. Or am I missing something= ? In any case, if the promotion is what is intended, 'nbytes' should be probably replaced with '(size_t) nbytes' to silence the warning and to make it explicit. Am So., 4. Apr. 2021 um 08:24 Uhr schrieb Jeffrey Walton : > On Sun, Apr 4, 2021 at 2:17 AM Marc Nieper-Wi=C3=9Fkirchen > wrote: > > > > GCC prints the following warning when compiling the new code: > > > > lib/xmalloc.c: In function 'xpalloc': > > lib/xmalloc.c:132:64: warning: comparison of integer expressions of > different signedness: 'long unsigned int' and 'idx_t' {aka 'long int'} > [-Wsign-compare] > > 132 | =3D ((INT_MULTIPLY_WRAPV (n, item_size, &nbytes) || SIZE_MA= X < > nbytes) > > > > If I understand the error message correctly, it is because 'nbytes' is = a > signed type while SIZE_MAX is unsigned. > > > > Does the comparison make any sense, by the way? > > Only for positive integers. > > If idx_t is negative, like -1, then -1 will be promoted to an unsigned > type and then -1 > 0. > > Jeff > --00000000000097189e05bf1fe559 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
SIZE_MAX could be defined as -1 promoted to an unsigned type, meaning th= at the unsigned comparison would always yield false. Or am I missing someth= ing?

=
In any c= ase, if the promotion is what is intended, 'nbytes' should be proba= bly replaced with '(size_t) nbytes' to silence the warning and to m= ake it explicit.


Am So., 4. Apr. 2021 um 08:24=C2=A0Uhr schrieb Jeffrey Wa= lton <noloader@gmail.com>:<= br>
On Sun, Apr 4, 2= 021 at 2:17 AM Marc Nieper-Wi=C3=9Fkirchen
<marc.n= ieper+gnu@gmail.com> wrote:
>
> GCC prints the following warning when compiling the new code:
>
> lib/xmalloc.c: In function 'xpalloc':
> lib/xmalloc.c:132:64: warning: comparison of integer expressions of di= fferent signedness: 'long unsigned int' and 'idx_t' {aka &#= 39;long int'} [-Wsign-compare]
>=C2=A0 =C2=A0132 |=C2=A0 =C2=A0 =C2=A0=3D ((INT_MULTIPLY_WRAPV (n, item= _size, &nbytes) || SIZE_MAX < nbytes)
>
> If I understand the error message correctly, it is because 'nbytes= ' is a signed type while SIZE_MAX is unsigned.
>
> Does the comparison make any sense, by the way?

Only for positive integers.

If idx_t is negative, like -1, then -1 will be promoted to an unsigned
type and then -1 > 0.

Jeff
--00000000000097189e05bf1fe559--