From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTPS id EC3D6385841E for ; Fri, 29 Oct 2021 08:30:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org EC3D6385841E Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-331-tmzew8zLNiyprYupxL9f4A-1; Fri, 29 Oct 2021 04:30:51 -0400 X-MC-Unique: tmzew8zLNiyprYupxL9f4A-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 18E921966358; Fri, 29 Oct 2021 08:30:50 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.39.194.250]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 38BAE60843; Fri, 29 Oct 2021 08:30:48 +0000 (UTC) From: Florian Weimer To: Siddhesh Poyarekar via Libc-alpha Cc: Siddhesh Poyarekar Subject: Re: [PATCH] Handle NULL input to malloc_usable_size [BZ #28506] References: <20211029031802.254600-1-siddhesh@sourceware.org> Date: Fri, 29 Oct 2021 10:30:46 +0200 In-Reply-To: <20211029031802.254600-1-siddhesh@sourceware.org> (Siddhesh Poyarekar via Libc-alpha's message of "Fri, 29 Oct 2021 08:48:02 +0530") Message-ID: <875ytgkzbd.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 29 Oct 2021 08:30:54 -0000 * Siddhesh Poyarekar via Libc-alpha: > size_t > __malloc_usable_size (void *m) > { > + size_t result =3D 0; > =20 > + if (m !=3D NULL) > + result =3D musable (m); > return result; > } Is there a reason for not writing it this way? size_t __malloc_usable_size (void *m) { if (m =3D=3D NULL) return 0; return musable (m); } The extra variable seems a bit =E2=80=A6 unnecessary? > diff --git a/malloc/tst-malloc-usable.c b/malloc/tst-malloc-usable.c > index a1074b782a..cd5c27cfcd 100644 > --- a/malloc/tst-malloc-usable.c > +++ b/malloc/tst-malloc-usable.c > @@ -21,29 +21,24 @@ > #include > #include > #include > +#include > +#include > =20 > static int > do_test (void) > { > size_t usable_size; > void *p =3D malloc (7); > =20 > + TEST_VERIFY_EXIT (p !=3D NULL); > usable_size =3D malloc_usable_size (p); > + TEST_VERIFY_EXIT (usable_size =3D=3D 7); You can use TEST_COMPARE here. > memset (p, 0, usable_size); > free (p); > + > + TEST_VERIFY_EXIT (malloc_usable_size (NULL) =3D=3D 0); And here. Thanks, Florian