From: Pedro Alves <pedro@palves.net>
To: Jan Beulich <jbeulich@suse.com>, Nick Clifton <nickc@redhat.com>
Cc: binutils@sourceware.org, Mark Harmstone <mark@harmstone.com>,
Alan Modra <amodra@gmail.com>
Subject: Re: [PATCH] ld: Sort section contributions in PDB files
Date: Tue, 21 Feb 2023 18:44:42 +0000 [thread overview]
Message-ID: <f4a99431-5da0-757d-17fb-3343dbf4a7d1@palves.net> (raw)
In-Reply-To: <6ab057e8-43aa-93b4-511c-348b3b2e23e3@suse.com>
On 2023-02-21 11:03 a.m., Jan Beulich via Binutils wrote:
> On 21.02.2023 11:49, Nick Clifton wrote:
>> On a related note - I would consider this line to be problematic:
>>
>> sc_in = xmalloc (num_sc * sizeof (struct in_sc));
>>
>> The code here implies that "sc_in" is a pointer to the "struct in_sc" type.
>> If at some future date the code is changed and the type of "sc_in" is changed
>> then the above line will still work, but the wrong amount of space will be
>> allocated.
>
> Oh, indeed, another pattern I would normally feel tempted to comment on, just
> that I've overlooked it this time.
>
>> So I would suggest changing it to either:
>>
>> sc_in = xmalloc (num_sc * sizeof (* sc_in));
>
> Yes.
>
>> Or:
>>
>> sc_in = xmalloc (num_sc * sizeof * sc_in); /* I like this version, but nobody else does ... :-) */
>
> Well ... * is commutative as a binary operator, so how about re-writing
> it to
>
> sc_in = xmalloc (num_sc * sc_in * sizeof);
>
> ;-) ?
>
>> Or:
>>
>> sc_in = XNEWVEC (typeof (sc_in), num_sc);
>
> I guess this one's the form that's best in line with what's used elsewhere
> in binutils.
'typeof' is a GNU extension, though.
Switch to C++ and use 'decltype'? :-D
next prev parent reply other threads:[~2023-02-21 18:44 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-20 14:13 Mark Harmstone
2023-02-21 8:26 ` Jan Beulich
2023-02-21 10:49 ` Nick Clifton
2023-02-21 11:03 ` Jan Beulich
2023-02-21 18:44 ` Pedro Alves [this message]
2023-02-22 5:48 ` Alan Modra
2023-02-22 7:08 ` Jan Beulich
2023-02-22 10:52 ` Alan Modra
2023-02-27 0:50 ` Mark Harmstone
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=f4a99431-5da0-757d-17fb-3343dbf4a7d1@palves.net \
--to=pedro@palves.net \
--cc=amodra@gmail.com \
--cc=binutils@sourceware.org \
--cc=jbeulich@suse.com \
--cc=mark@harmstone.com \
--cc=nickc@redhat.com \
/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).