浏览代码

Fix #425604 - Conditional jump or move depends on uninitialised value(s)
It occurs on first occurence of slave timeout (found with Valgrind 3.3.0).
Reported by Henrik Munktell.

Stéphane Raimbault 16 年之前
父节点
当前提交
effaf92923
共有 2 个文件被更改,包括 10 次插入4 次删除
  1. 6 1
      NEWS
  2. 4 3
      src/modbus.c

+ 6 - 1
NEWS

@@ -14,6 +14,11 @@ libmodbus 2.2.0 (2009-XX-01)
   Reported and tested by Yishin Li.
 - Fix #378981 - CRC error on RTU response doesn't return negative value
   Reported by Henrik Munktell.
+- Fix report slave ID request
+  Patch (bzr) provided by Paul Fertser .
+- Fix #425604 - Conditional jump or move depends on uninitialised value(s)
+  Occurs on first occurence of slave timeout.
+  Reported by Henrik Munktell.
 
 libmodbus 2.0.3 (2009-03-22)
 ============================
@@ -63,7 +68,7 @@ libmodbus 2.0.0 (2008-05-18)
 - Declare many static functions and const arrays
 - Enhance an integer division
 - The GNU licences LGPL and GPL are in version 3
-- Debian and RPM packages (#224496) 
+- Debian and RPM packages (#224496)
 - Many cleanups
 - Fix #159443 reported by Stefan Bisanz
   Index of incoming data in force multiple coils function

+ 4 - 3
src/modbus.c

@@ -532,6 +532,10 @@ static int receive_msg(modbus_param_t *mb_param,
         enum { FUNCTION, BYTE, COMPLETE };
         int state;
 
+        /* Initialize the return length before a call to WAIT_DATA because a
+         * time out can quit the function. */
+        (*p_msg_length) = 0;
+
         if (mb_param->debug) {
                 if (msg_length_computed == MSG_LENGTH_UNDEFINED)
                         printf("Waiting for a message...\n");
@@ -566,10 +570,7 @@ static int receive_msg(modbus_param_t *mb_param,
         select_ret = 0;
         WAIT_DATA();
 
-        /* Initialize the readin the message */
-        (*p_msg_length) = 0;
         p_msg = msg;
-
         while (select_ret) {
                 if (mb_param->type_com == RTU)
                         read_ret = read(mb_param->fd, p_msg, length_to_read);