فهرست منبع

Improve handling of arguments of the macros

The arguments are surrounded by parentheses to be evaluated first.
Stéphane Raimbault 14 سال پیش
والد
کامیت
39ccdf3234
1فایلهای تغییر یافته به همراه6 افزوده شده و 6 حذف شده
  1. 6 6
      src/modbus.h

+ 6 - 6
src/modbus.h

@@ -187,14 +187,14 @@ int modbus_reply_exception(modbus_t *ctx, const uint8_t *req,
  * UTILS FUNCTIONS
  **/
 
-#define MODBUS_GET_HIGH_BYTE(data) ((data >> 8) & 0xFF)
-#define MODBUS_GET_LOW_BYTE(data) (data & 0xFF)
-#define MODBUS_GET_INT32_FROM_INT16(tab_int16, index) ((tab_int16[index] << 16) + tab_int16[index + 1])
-#define MODBUS_GET_INT16_FROM_INT8(tab_int8, index) ((tab_int8[index] << 8) + tab_int8[index + 1])
+#define MODBUS_GET_HIGH_BYTE(data) (((data) >> 8) & 0xFF)
+#define MODBUS_GET_LOW_BYTE(data) ((data) & 0xFF)
+#define MODBUS_GET_INT32_FROM_INT16(tab_int16, index) ((tab_int16[(index)] << 16) + tab_int16[(index) + 1])
+#define MODBUS_GET_INT16_FROM_INT8(tab_int8, index) ((tab_int8[(index)] << 8) + tab_int8[(index) + 1])
 #define MODBUS_SET_INT16_TO_INT8(tab_int8, index, value) \
     do { \
-       tab_int8[index] = value >> 8; \
-       tab_int8[index + 1] = value & 0xFF; \
+        tab_int8[(index)] = (value) >> 8;  \
+        tab_int8[(index) + 1] = (value) & 0xFF; \
     } while (0)
 
 void modbus_set_bits_from_byte(uint8_t *dest, int address, const uint8_t value);