Эх сурвалжийг харах

Test return code of receive_msg_req to have an explicit error path

Stéphane Raimbault 14 жил өмнө
parent
commit
70a2e6e624
1 өөрчлөгдсөн 3 нэмэгдсэн , 1 устгасан
  1. 3 1
      src/modbus.c

+ 3 - 1
src/modbus.c

@@ -1295,10 +1295,12 @@ static int read_registers(modbus_t *ctx, int function, int addr, int nb,
         int i;
 
         rc = receive_msg_req(ctx, req, rsp);
+        if (rc == -1) {
+            return -1;
+        }
 
         offset = TAB_HEADER_LENGTH[ctx->type_com];
 
-        /* If rc is negative, the loop is jumped ! */
         for (i = 0; i < rc; i++) {
             /* shift reg hi_byte to temp OR with lo_byte */
             data_dest[i] = (rsp[offset + 2 + (i << 1)] << 8) |