diff options
| author | Tom Tung <shes050117@gmail.com> | 2022-08-12 15:43:49 +0800 |
|---|---|---|
| committer | Alexander Amelkin <mocbuhtig@amelkin.msk.ru> | 2022-08-28 20:23:25 +0300 |
| commit | 46fd8d942cb1e3c7bfa491c9e129b7f72de526c0 (patch) | |
| tree | 712e4e6a2ee44799dad57a49e162280dcb04fe74 /include | |
| parent | a1dc78c4566734075c433ca61e71bd18c7058c6d (diff) | |
| download | ipmitool-46fd8d942cb1e3c7bfa491c9e129b7f72de526c0.tar.gz | |
Cast type before the left shift
Building ipmitool with UBSAN and I got:
```
...
xxx/ipmitool/include/ipmitool/helper.h:191:14: runtime error: left shift of 160
by 24 places cannot be represented in type 'int'
#0 0x55bddaa56f11 in ipmi32toh
xxx/ipmitool/include/ipmitool/helper.h:191:14
```
Tested: with this, I tested ipmitool again and the issue disappeared.
Resolved: ipmitool/ipmitool#352
Signed-off-by: Tom Tung <shes050117@gmail.com>
Diffstat (limited to 'include')
| -rw-r--r-- | include/ipmitool/helper.h | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/include/ipmitool/helper.h b/include/ipmitool/helper.h index 23dbc63..79a5c5b 100644 --- a/include/ipmitool/helper.h +++ b/include/ipmitool/helper.h @@ -152,7 +152,7 @@ static inline uint16_t ipmi16toh(void *ipmi16) uint8_t *ipmi = (uint8_t *)ipmi16; uint16_t h; - h = ipmi[1] << 8; /* MSB */ + h = (uint16_t)ipmi[1] << 8; /* MSB */ h |= ipmi[0]; /* LSB */ return h; @@ -169,7 +169,7 @@ static inline uint32_t ipmi24toh(void *ipmi24) uint8_t *ipmi = (uint8_t *)ipmi24; uint32_t h = 0; - h = ipmi[2] << 16; /* MSB */ + h = (uint32_t)ipmi[2] << 16; /* MSB */ h |= ipmi[1] << 8; h |= ipmi[0]; /* LSB */ @@ -188,7 +188,7 @@ static inline uint32_t ipmi32toh(void *ipmi32) uint8_t *ipmi = ipmi32; uint32_t h; - h = ipmi[3] << 24; /* MSB */ + h = (uint32_t)ipmi[3] << 24; /* MSB */ h |= ipmi[2] << 16; h |= ipmi[1] << 8; h |= ipmi[0]; /* LSB */ |
