Commit 0814ecf778c8d9b3e8bbf520503849de4eee7710

Authored by José Bollo
Committed by Stéphane Raimbault
1 parent 7f48e0fd

Fix warning issues

When compiling with gcc and option -Wconversion it fixes the
warning message

  warning: conversion from ‘X’ {aka ‘x’} to ‘Y’ {aka ‘y’} may change value

Signed-off-by: José Bollo <jose.bollo@iot.bzh>
Showing 1 changed file with 14 additions and 10 deletions
src/modbus.h
@@ -249,24 +249,28 @@ MODBUS_API int modbus_reply_exception(modbus_t *ctx, const uint8_t *req, @@ -249,24 +249,28 @@ MODBUS_API int modbus_reply_exception(modbus_t *ctx, const uint8_t *req,
249 ((int64_t)tab_int16[(index) + 1] << 32) | \ 249 ((int64_t)tab_int16[(index) + 1] << 32) | \
250 ((int64_t)tab_int16[(index) + 2] << 16) | \ 250 ((int64_t)tab_int16[(index) + 2] << 16) | \
251 (int64_t)tab_int16[(index) + 3]) 251 (int64_t)tab_int16[(index) + 3])
252 -#define MODBUS_GET_INT32_FROM_INT16(tab_int16, index) ((tab_int16[(index)] << 16) | tab_int16[(index) + 1])  
253 -#define MODBUS_GET_INT16_FROM_INT8(tab_int8, index) ((tab_int8[(index)] << 8) | tab_int8[(index) + 1]) 252 +#define MODBUS_GET_INT32_FROM_INT16(tab_int16, index) \
  253 + (((int32_t)tab_int16[(index) ] << 16) | \
  254 + (int32_t)tab_int16[(index) + 1])
  255 +#define MODBUS_GET_INT16_FROM_INT8(tab_int8, index) \
  256 + (((int16_t)tab_int8[(index) ] << 8) | \
  257 + (int16_t)tab_int8[(index) + 1])
254 #define MODBUS_SET_INT16_TO_INT8(tab_int8, index, value) \ 258 #define MODBUS_SET_INT16_TO_INT8(tab_int8, index, value) \
255 do { \ 259 do { \
256 - tab_int8[(index)] = (value) >> 8; \  
257 - tab_int8[(index) + 1] = (value) & 0xFF; \ 260 + ((int8_t*)(tab_int8))[(index) ] = (int8_t)((value) >> 8); \
  261 + ((int8_t*)(tab_int8))[(index) + 1] = (int8_t)(value); \
258 } while (0) 262 } while (0)
259 #define MODBUS_SET_INT32_TO_INT16(tab_int16, index, value) \ 263 #define MODBUS_SET_INT32_TO_INT16(tab_int16, index, value) \
260 do { \ 264 do { \
261 - tab_int16[(index) ] = (value) >> 16; \  
262 - tab_int16[(index) + 1] = (value); \ 265 + ((int16_t*)(tab_int16))[(index) ] = (int16_t)((value) >> 16); \
  266 + ((int16_t*)(tab_int16))[(index) + 1] = (int16_t)(value); \
263 } while (0) 267 } while (0)
264 #define MODBUS_SET_INT64_TO_INT16(tab_int16, index, value) \ 268 #define MODBUS_SET_INT64_TO_INT16(tab_int16, index, value) \
265 do { \ 269 do { \
266 - tab_int16[(index) ] = (value) >> 48; \  
267 - tab_int16[(index) + 1] = (value) >> 32; \  
268 - tab_int16[(index) + 2] = (value) >> 16; \  
269 - tab_int16[(index) + 3] = (value); \ 270 + ((int16_t*)(tab_int16))[(index) ] = (int16_t)((value) >> 48); \
  271 + ((int16_t*)(tab_int16))[(index) + 1] = (int16_t)((value) >> 32); \
  272 + ((int16_t*)(tab_int16))[(index) + 2] = (int16_t)((value) >> 16); \
  273 + ((int16_t*)(tab_int16))[(index) + 3] = (int16_t)(value); \
270 } while (0) 274 } while (0)
271 275
272 MODBUS_API void modbus_set_bits_from_byte(uint8_t *dest, int idx, const uint8_t value); 276 MODBUS_API void modbus_set_bits_from_byte(uint8_t *dest, int idx, const uint8_t value);