From: "Martin Liška" <mliska@suse.cz>
To: Alan Modra <amodra@gmail.com>
Cc: gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] libiberty: stop using PTR macro.
Date: Tue, 10 May 2022 17:33:16 +0200 [thread overview]
Message-ID: <7d24cbe2-ed68-f798-fbed-5ec7f6b56152@suse.cz> (raw)
In-Reply-To: <Ynp0or1AunV1ZXL1@squeak.grove.modra.org>
[-- Attachment #1: Type: text/plain, Size: 1843 bytes --]
On 5/10/22 16:20, Alan Modra wrote:
> On Tue, May 10, 2022 at 10:56:22AM +0200, Martin Liška wrote:
>
>> diff --git a/libiberty/hashtab.c b/libiberty/hashtab.c
>
>> @@ -457,15 +457,15 @@ htab_empty (htab_t htab)
>> else if (htab->free_with_arg_f != NULL)
>> (*htab->free_with_arg_f) (htab->alloc_arg, htab->entries);
>> if (htab->alloc_with_arg_f != NULL)
>> - htab->entries = (PTR *) (*htab->alloc_with_arg_f) (htab->alloc_arg, nsize,
>> - sizeof (PTR *));
>> + htab->entries = (void **) (*htab->alloc_with_arg_f) (htab->alloc_arg, nsize,
>> + sizeof (void **));
>
> Here, and below, the code should really be using "sizeof (void *)".
> You may as well fix that nit while you're at it. Also, indentation
> looks wrong.
>
>> else
>> - htab->entries = (PTR *) (*htab->alloc_f) (nsize, sizeof (PTR *));
>> + htab->entries = (void **) (*htab->alloc_f) (nsize, sizeof (void **));
>> htab->size = nsize;
>> htab->size_prime_index = nindex;
>> }
>> else
>> - memset (entries, 0, size * sizeof (PTR));
>> + memset (entries, 0, size * sizeof (void *));
>> htab->n_deleted = 0;
>> htab->n_elements = 0;
>> }
>
>> @@ -543,10 +543,10 @@ htab_expand (htab_t htab)
>> }
>>
>> if (htab->alloc_with_arg_f != NULL)
>> - nentries = (PTR *) (*htab->alloc_with_arg_f) (htab->alloc_arg, nsize,
>> - sizeof (PTR *));
>> + nentries = (void **) (*htab->alloc_with_arg_f) (htab->alloc_arg, nsize,
>> + sizeof (void **));
>> else
>> - nentries = (PTR *) (*htab->alloc_f) (nsize, sizeof (PTR *));
>> + nentries = (void **) (*htab->alloc_f) (nsize, sizeof (void **));
>> if (nentries == NULL)
>> return 0;
>> htab->entries = nentries;
>
> Here too.
>
Thanks for the comments, I'm going to push the following patch.
Martin
[-- Attachment #2: 0001-libiberty-fix-type-in-allocation.patch --]
[-- Type: text/x-patch, Size: 1649 bytes --]
From 5dac43b43c3999f94b451cd7925e24d8e7c38a7a Mon Sep 17 00:00:00 2001
From: Martin Liska <mliska@suse.cz>
Date: Tue, 10 May 2022 17:31:24 +0200
Subject: [PATCH] libiberty: fix type in allocation
The allocation function alloc_f is called for nsize
items where each is of type void *.
libiberty/ChangeLog:
* hashtab.c (htab_empty): Use void * type instead of void **.
(htab_expand): Likewise.
Co-Authored-By: Alan Modra <amodra@gmail.com>
---
libiberty/hashtab.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/libiberty/hashtab.c b/libiberty/hashtab.c
index f7621cd47e5..470d3e66c32 100644
--- a/libiberty/hashtab.c
+++ b/libiberty/hashtab.c
@@ -458,9 +458,9 @@ htab_empty (htab_t htab)
(*htab->free_with_arg_f) (htab->alloc_arg, htab->entries);
if (htab->alloc_with_arg_f != NULL)
htab->entries = (void **) (*htab->alloc_with_arg_f) (htab->alloc_arg, nsize,
- sizeof (void **));
+ sizeof (void *));
else
- htab->entries = (void **) (*htab->alloc_f) (nsize, sizeof (void **));
+ htab->entries = (void **) (*htab->alloc_f) (nsize, sizeof (void *));
htab->size = nsize;
htab->size_prime_index = nindex;
}
@@ -544,9 +544,9 @@ htab_expand (htab_t htab)
if (htab->alloc_with_arg_f != NULL)
nentries = (void **) (*htab->alloc_with_arg_f) (htab->alloc_arg, nsize,
- sizeof (void **));
+ sizeof (void *));
else
- nentries = (void **) (*htab->alloc_f) (nsize, sizeof (void **));
+ nentries = (void **) (*htab->alloc_f) (nsize, sizeof (void *));
if (nentries == NULL)
return 0;
htab->entries = nentries;
--
2.36.0
prev parent reply other threads:[~2022-05-10 15:33 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-10 8:56 Martin Liška
2022-05-10 13:37 ` Jeff Law
2022-05-10 13:50 ` Eric Gallager
2022-05-10 14:03 ` Martin Liška
2022-05-10 14:20 ` Alan Modra
2022-05-10 15:33 ` Martin Liška [this message]
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=7d24cbe2-ed68-f798-fbed-5ec7f6b56152@suse.cz \
--to=mliska@suse.cz \
--cc=amodra@gmail.com \
--cc=gcc-patches@gcc.gnu.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).