packages/libs/libmodbus/patches/0001-Fixed-MODBUS_GET_-macros-in-case-of-negative-values.patch
Michael Heimpold 99d6731ed9 libmodbus: update to 3.1.6
Also fix the license information: in older versions the test programs
were GPL 3 licensed, but meanwhile it changed to BSD license.
But since this package only packages the library itself, we can
safely focus only on the LGPL here which covers the library itself.

While at, fix a minor nitpick during library symlink installation.

Signed-off-by: Michael Heimpold <mhei@heimpold.de>
2019-09-16 23:19:15 +02:00

35 lines
1.8 KiB
Diff

From f1eb4bc7ccb09cd8d19ab641ee37637f8c34d16d Mon Sep 17 00:00:00 2001
From: i-ky <gl.ivanovsky@gmail.com>
Date: Tue, 10 Jul 2018 15:58:45 +0300
Subject: [PATCH] Fixed MODBUS_GET_* macros in case of negative values
In case resulting value should be negative it is incorrect to use '+' operator to construct it from pieces, because highest bytes will result in negative number after bitwise shift while others will stay positive. Replacing addition with '|' should solve the issue.
---
src/modbus.h | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/src/modbus.h b/src/modbus.h
index f6e9a5f..c63f5ce 100644
--- a/src/modbus.h
+++ b/src/modbus.h
@@ -245,12 +245,12 @@ MODBUS_API int modbus_reply_exception(modbus_t *ctx, const uint8_t *req,
#define MODBUS_GET_HIGH_BYTE(data) (((data) >> 8) & 0xFF)
#define MODBUS_GET_LOW_BYTE(data) ((data) & 0xFF)
#define MODBUS_GET_INT64_FROM_INT16(tab_int16, index) \
- (((int64_t)tab_int16[(index) ] << 48) + \
- ((int64_t)tab_int16[(index) + 1] << 32) + \
- ((int64_t)tab_int16[(index) + 2] << 16) + \
+ (((int64_t)tab_int16[(index) ] << 48) | \
+ ((int64_t)tab_int16[(index) + 1] << 32) | \
+ ((int64_t)tab_int16[(index) + 2] << 16) | \
(int64_t)tab_int16[(index) + 3])
-#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_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; \
--
2.17.1