This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH v2 1/5] mips: Do not malloc on getdents64 fallback
- From: Florian Weimer <fweimer at redhat dot com>
- To: Adhemerval Zanella <adhemerval dot zanella at linaro dot org>
- Cc: libc-alpha at sourceware dot org
- Date: Tue, 08 Oct 2019 20:52:42 +0200
- Subject: Re: [PATCH v2 1/5] mips: Do not malloc on getdents64 fallback
- References: <20190731183136.21545-1-adhemerval.zanella@linaro.org> <87k1av6kuh.fsf@oldenburg2.str.redhat.com> <49dc9440-d9a5-112f-9ec6-b62f4c0bcdf2@linaro.org> <87zhjmvoow.fsf@oldenburg2.str.redhat.com> <30395e41-d6c9-4fce-ca7a-933d55900fc7@linaro.org> <87imp0flym.fsf@oldenburg2.str.redhat.com> <703d65b6-82bd-f557-7257-0fdd9cedb2f4@linaro.org>
* 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.
> + 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.
> + 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.
Thanks,
Florian