[PATCH v2] lib: fix pointer of type 'void *' used in arithmetic

Jukka Laitinen jukkax at ssrc.tii.ae
Thu Jan 13 03:03:13 PST 2022


Thanks for comments!


On 13.1.2022 12.52, Damien Le Moal wrote:
> [Re-sending this since my emails end up being empty...]
>
> On 2022/01/13 17:49, Jukka Laitinen wrote:
>> Using "void *" in arithmetic causes errors with strict compiler settings:
>> "error: pointer of type 'void *' used in arithmetic [-Werror=pointer-arith]"
>>
>> Just remove these by calculating on "char *" where 1-byte data size is assumed
> s/Just Remove/Avoid
> (and nit: add a period at the end of the sentence)

I will add these to patchset v3 !

>
> I would also suggest a cast to unsigned long instead of char *. unsigned long is
> more common/natural for addresses arithmetic.

You are right, that is is more natural to do arithmetic on integers than 
pointers.

However, I don't like to change pointer to unsigned long and back for 
several reasons; one being that afaik no stardard states that 
sizeof(unsigned long) == sizeof(void *). And even while this is a 
typical case, there is quarantee that this wouldn't have other side 
effects (such as padding bits ...).

There is intptr_t and uintptr_t in C99 as optional for this purpose, but 
those don't exist in all C/C++ standards.

So; I'd rather just do pointer arithmetic when the intention is to do 
pointer arithmetic :)





More information about the opensbi mailing list