3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-04-07 01:54:10 +00:00

Fix fstGetUint32 crash on mips64el due to misaligned access

See https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1025307
This commit is contained in:
Daniel Gröber 2023-08-27 15:01:27 +02:00
parent de54cf1a0c
commit e4189ddfd1

View file

@ -348,17 +348,17 @@ static void *fstMmap2(size_t __len, int __fd, fst_off_t __off)
#ifdef FST_DO_MISALIGNED_OPS #ifdef FST_DO_MISALIGNED_OPS
#define fstGetUint32(x) (*(uint32_t *)(x)) #define fstGetUint32(x) (*(uint32_t *)(x))
#else #else
static uint32_t fstGetUint32(unsigned char *mem) static inline uint32_t fstGetUint32(unsigned char *mem)
{ {
uint32_t u32; union {
unsigned char *buf = (unsigned char *)(&u32); uint8_t u8[sizeof(uint32_t)];
uint32_t u32;
} u;
buf[0] = mem[0]; for (size_t i=0; i < sizeof(u.u8); i++)
buf[1] = mem[1]; u.u8[i] = mem[i];
buf[2] = mem[2];
buf[3] = mem[3];
return (*(uint32_t *)buf); return u.u32;
} }
#endif #endif