mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-04-28 11:47:48 +02:00
Fix any remaning aliasing rules with propper memcpy wrappers
This commit is contained in:
parent
1636187e26
commit
700c53e60a
11 changed files with 140 additions and 94 deletions
64
I2PEndian.h
64
I2PEndian.h
|
@ -47,27 +47,73 @@ uint64_t be64toh(uint64_t big64);
|
|||
|
||||
#endif
|
||||
|
||||
inline uint16_t buf16toh(const uint8_t *buf)
|
||||
{
|
||||
uint16_t b16;
|
||||
memcpy(&b16, buf, sizeof(uint16_t));
|
||||
return b16;
|
||||
}
|
||||
|
||||
inline uint32_t buf32toh(const uint8_t *buf)
|
||||
{
|
||||
uint32_t b32;
|
||||
memcpy(&b32, buf, sizeof(uint32_t));
|
||||
return b32;
|
||||
}
|
||||
|
||||
inline uint64_t buf64toh(const uint8_t *buf)
|
||||
{
|
||||
uint64_t b64;
|
||||
memcpy(&b64, buf, sizeof(uint64_t));
|
||||
return b64;
|
||||
}
|
||||
|
||||
inline uint16_t bufbe16toh(const uint8_t *buf)
|
||||
{
|
||||
uint16_t big16;
|
||||
memcpy(&big16, buf, sizeof(uint16_t));
|
||||
return be16toh(big16);
|
||||
return be16toh(buf16toh(buf));
|
||||
}
|
||||
|
||||
inline uint32_t bufbe32toh(const uint8_t *buf)
|
||||
{
|
||||
uint32_t big32;
|
||||
memcpy(&big32, buf, sizeof(uint32_t));
|
||||
return be32toh(big32);
|
||||
return be32toh(buf32toh(buf));
|
||||
}
|
||||
|
||||
inline uint64_t bufbe64toh(const uint8_t *buf)
|
||||
{
|
||||
uint64_t big64;
|
||||
memcpy(&big64, buf, sizeof(uint64_t));
|
||||
return be64toh(big64);
|
||||
return be64toh(buf64toh(buf));
|
||||
}
|
||||
|
||||
inline void htobuf16(uint8_t *buf, uint16_t b16)
|
||||
{
|
||||
memcpy(buf, &b16, sizeof(uint16_t));
|
||||
}
|
||||
|
||||
inline void htobuf32(uint8_t *buf, uint32_t b32)
|
||||
{
|
||||
memcpy(buf, &b32, sizeof(uint32_t));
|
||||
}
|
||||
|
||||
inline void htobuf64(uint8_t *buf, uint64_t b64)
|
||||
{
|
||||
memcpy(buf, &b64, sizeof(uint64_t));
|
||||
}
|
||||
|
||||
inline void htobe16buf(uint8_t *buf, uint16_t big16)
|
||||
{
|
||||
htobuf16(buf, htobe16(big16));
|
||||
}
|
||||
|
||||
inline void htobe32buf(uint8_t *buf, uint32_t big32)
|
||||
{
|
||||
htobuf32(buf, htobe32(big32));
|
||||
}
|
||||
|
||||
inline void htobe64buf(uint8_t *buf, uint64_t big64)
|
||||
{
|
||||
htobuf64(buf, htobe64(big64));
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif // I2PENDIAN_H__
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue