[PATCH v2 1/5] mips: Do not malloc on getdents64 fallback
Adhemerval Zanella
adhemerval.zanella@linaro.org
Tue Oct 8 19:52:00 GMT 2019
On 08/10/2019 15:52, Florian Weimer wrote:
> * Adhemerval Zanella:
>
>> +#define DP_MEMBER(src, type, member) \
>> + (__typeof__((type){0}.member) *) \
>> + memcpy (&((__typeof__((type){0}.member)){0}), \
>> + ((char *)(src) + offsetof (type, member)), \
>> + sizeof ((type){0}.member))
>
> Please add a comment that this is used to avoid an aliasing violation.
Ack.
>
>> + memcpy (((char *)(dp) + offsetof (struct dirent64, d_ino)),
>> + DP_MEMBER (kdp, struct kernel_dirent, d_ino),
>> + sizeof ((struct dirent64){0}.d_ino));
>> + memcpy (((char *)(dp) + offsetof (struct dirent64, d_off)),
>> + DP_MEMBER (kdp, struct kernel_dirent, d_ino),
>> + sizeof ((struct dirent64){0}.d_ino));
>> + memcpy (&last_offset,
>> + DP_MEMBER (kdp, struct kernel_dirent, d_off),
>> + sizeof (last_offset));
>
> I think you should be able to use:
>
> last_offset = *DP_MEMBER (kdp, struct kernel_dirent, d_off);
>
> last_offset has the correct type.
Ack.
>
>> + memcpy (DP_MEMBER (dp, struct dirent64, d_reclen), &new_reclen,
>> + sizeof ((struct dirent64){0}.d_reclen));
>
> That looks wrong. DP_MEMBER (dp, struct dirent64, d_reclen) is a
> temporary object, so the outer memcpy is dead.
Sigh, indeed. I changed to:
memcpy (((char *)(dp) + offsetof (struct dirent64, d_reclen)),
&new_reclen, sizeof ((struct dirent64){0}.d_reclen));
>
> Thanks,
> Florian
>
I hope I got this right this time...
More information about the Libc-alpha
mailing list