From: Florian Weimer <fweimer@redhat.com>
To: Siddhesh Poyarekar via Libc-alpha <libc-alpha@sourceware.org>
Cc: Siddhesh Poyarekar <siddhesh@sourceware.org>
Subject: Re: [PATCH] Handle NULL input to malloc_usable_size [BZ #28506]
Date: Fri, 29 Oct 2021 10:30:46 +0200 [thread overview]
Message-ID: <875ytgkzbd.fsf@oldenburg.str.redhat.com> (raw)
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")
* Siddhesh Poyarekar via Libc-alpha:
> size_t
> __malloc_usable_size (void *m)
> {
> + size_t result = 0;
>
> + if (m != NULL)
> + result = musable (m);
> return result;
> }
Is there a reason for not writing it this way?
size_t
__malloc_usable_size (void *m)
{
if (m == NULL)
return 0;
return musable (m);
}
The extra variable seems a bit … 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 <malloc.h>
> #include <string.h>
> #include <stdio.h>
> +#include <support/support.h>
> +#include <support/check.h>
>
> static int
> do_test (void)
> {
> size_t usable_size;
> void *p = malloc (7);
>
> + TEST_VERIFY_EXIT (p != NULL);
> usable_size = malloc_usable_size (p);
> + TEST_VERIFY_EXIT (usable_size == 7);
You can use TEST_COMPARE here.
> memset (p, 0, usable_size);
> free (p);
> +
> + TEST_VERIFY_EXIT (malloc_usable_size (NULL) == 0);
And here.
Thanks,
Florian
next prev parent reply other threads:[~2021-10-29 8:30 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-29 3:18 Siddhesh Poyarekar
2021-10-29 8:30 ` Florian Weimer [this message]
2021-10-29 8:55 ` [PATCH v2] " Siddhesh Poyarekar
2021-10-29 9:00 ` Richard W.M. Jones
2021-10-29 9:06 ` Florian Weimer
2021-10-29 9:25 ` [COMMITTED] " Siddhesh Poyarekar
2021-10-29 9:27 ` Florian Weimer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=875ytgkzbd.fsf@oldenburg.str.redhat.com \
--to=fweimer@redhat.com \
--cc=libc-alpha@sourceware.org \
--cc=siddhesh@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).