From 8e4a5021e64431cecfbb16c00f6f676709e1c803 Mon Sep 17 00:00:00 2001 From: Giovanni Frigo Date: Tue, 12 Jul 2016 08:18:03 +0200 Subject: [PATCH] Fix LIBMODBUS_VERSION_HEX encoding (closes #345) The result of LIBMODBUS_VERSION_HEX is left-shifted by an extra factor of 8 bits. For example, current implementation for version 1.2.3 would be encoded like 0x01020300 instead of 0x010203. --- src/modbus-version.h.in | 8 ++++---- tests/version.c | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/modbus-version.h.in b/src/modbus-version.h.in index d2dcac8e3..8473d6597 100644 --- a/src/modbus-version.h.in +++ b/src/modbus-version.h.in @@ -35,10 +35,10 @@ */ #define LIBMODBUS_VERSION_STRING "@LIBMODBUS_VERSION@" -/* Numerically encoded version, like 0x010203 */ -#define LIBMODBUS_VERSION_HEX ((LIBMODBUS_VERSION_MAJOR << 24) | \ - (LIBMODBUS_VERSION_MINOR << 16) | \ - (LIBMODBUS_VERSION_MICRO << 8)) +/* Numerically encoded version, eg. v1.2.3 is 0x010203 */ +#define LIBMODBUS_VERSION_HEX ((LIBMODBUS_VERSION_MAJOR << 16) | \ + (LIBMODBUS_VERSION_MINOR << 8) | \ + (LIBMODBUS_VERSION_MICRO << 0)) /* Evaluates to True if the version is greater than @major, @minor and @micro */ diff --git a/tests/version.c b/tests/version.c index e830a38ef..d6db67966 100644 --- a/tests/version.c +++ b/tests/version.c @@ -9,7 +9,7 @@ int main(void) { - printf("Compiled with libmodbus version %s (%08X)\n", LIBMODBUS_VERSION_STRING, LIBMODBUS_VERSION_HEX); + printf("Compiled with libmodbus version %s (%06X)\n", LIBMODBUS_VERSION_STRING, LIBMODBUS_VERSION_HEX); printf("Linked with libmodbus version %d.%d.%d\n", libmodbus_version_major, libmodbus_version_minor, libmodbus_version_micro);