Commit 39ccdf3234b7ba57b0179d7a931543eaa0aa8703

Authored by Stéphane Raimbault
1 parent f2f42c01

Improve handling of arguments of the macros

The arguments are surrounded by parentheses to be evaluated first.
Showing 1 changed file with 6 additions and 6 deletions
src/modbus.h
... ... @@ -187,14 +187,14 @@ int modbus_reply_exception(modbus_t *ctx, const uint8_t *req,
187 187 * UTILS FUNCTIONS
188 188 **/
189 189  
190   -#define MODBUS_GET_HIGH_BYTE(data) ((data >> 8) & 0xFF)
191   -#define MODBUS_GET_LOW_BYTE(data) (data & 0xFF)
192   -#define MODBUS_GET_INT32_FROM_INT16(tab_int16, index) ((tab_int16[index] << 16) + tab_int16[index + 1])
193   -#define MODBUS_GET_INT16_FROM_INT8(tab_int8, index) ((tab_int8[index] << 8) + tab_int8[index + 1])
  190 +#define MODBUS_GET_HIGH_BYTE(data) (((data) >> 8) & 0xFF)
  191 +#define MODBUS_GET_LOW_BYTE(data) ((data) & 0xFF)
  192 +#define MODBUS_GET_INT32_FROM_INT16(tab_int16, index) ((tab_int16[(index)] << 16) + tab_int16[(index) + 1])
  193 +#define MODBUS_GET_INT16_FROM_INT8(tab_int8, index) ((tab_int8[(index)] << 8) + tab_int8[(index) + 1])
194 194 #define MODBUS_SET_INT16_TO_INT8(tab_int8, index, value) \
195 195 do { \
196   - tab_int8[index] = value >> 8; \
197   - tab_int8[index + 1] = value & 0xFF; \
  196 + tab_int8[(index)] = (value) >> 8; \
  197 + tab_int8[(index) + 1] = (value) & 0xFF; \
198 198 } while (0)
199 199  
200 200 void modbus_set_bits_from_byte(uint8_t *dest, int address, const uint8_t value);
... ...