[PATCH] ld: Sort section contributions in PDB files

Jan Beulich jbeulich@suse.com
Tue Feb 21 11:03:29 GMT 2023


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.

Jan


More information about the Binutils mailing list