[PATCH] ftw.c: Check for "." and ".." branchlessly
Xi Ruoyao
xry111@xry111.site
Sun Sep 24 11:29:02 GMT 2023
On Sun, 2023-09-24 at 13:45 +0700, James Tirta Halim wrote:
> +static int
> +is_relative (const char *fname)
> +{
> + typedef uint16_t w2 __attribute__ ((__may_alias__));
> + typedef uint32_t w4 __attribute__ ((__may_alias__));
> + const uint16_t n1 = '.' | '\0' SH 8;
> + const uint32_t n2 = '.' | '.' SH 8 | '\0' SH 16;
> + return (*(w2 *)fname == n1) | ((*(w4 *)fname | '\0' SH 24) ==
> n2);
> +}
No. The unaligned access will cause segmentation fault or bus error on
some architectures.
--
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University
More information about the Libc-alpha
mailing list