mirror of
https://github.com/littlefs-project/littlefs.git
synced 2025-10-14 02:43:30 +08:00
Merge pull request #1100 from selimkeles/fix/bitshift_overflow
fix: added uint32_t cast to the bitshift places
This commit is contained in:
16
lfs_util.h
16
lfs_util.h
@@ -195,10 +195,10 @@ static inline uint32_t lfs_fromle32(uint32_t a) {
|
|||||||
(defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__))
|
(defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__))
|
||||||
return __builtin_bswap32(a);
|
return __builtin_bswap32(a);
|
||||||
#else
|
#else
|
||||||
return (((uint8_t*)&a)[0] << 0) |
|
return ((uint32_t)((uint8_t*)&a)[0] << 0) |
|
||||||
(((uint8_t*)&a)[1] << 8) |
|
((uint32_t)((uint8_t*)&a)[1] << 8) |
|
||||||
(((uint8_t*)&a)[2] << 16) |
|
((uint32_t)((uint8_t*)&a)[2] << 16) |
|
||||||
(((uint8_t*)&a)[3] << 24);
|
((uint32_t)((uint8_t*)&a)[3] << 24);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -218,10 +218,10 @@ static inline uint32_t lfs_frombe32(uint32_t a) {
|
|||||||
(defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
|
(defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
|
||||||
return a;
|
return a;
|
||||||
#else
|
#else
|
||||||
return (((uint8_t*)&a)[0] << 24) |
|
return ((uint32_t)((uint8_t*)&a)[0] << 24) |
|
||||||
(((uint8_t*)&a)[1] << 16) |
|
((uint32_t)((uint8_t*)&a)[1] << 16) |
|
||||||
(((uint8_t*)&a)[2] << 8) |
|
((uint32_t)((uint8_t*)&a)[2] << 8) |
|
||||||
(((uint8_t*)&a)[3] << 0);
|
((uint32_t)((uint8_t*)&a)[3] << 0);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user