This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH v2 1/5] mips: Do not malloc on getdents64 fallback


* 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]