stephane / libmodbus

A Modbus library for Linux, Mac OS, FreeBSD and Windows
http://libmodbus.org
GNU Lesser General Public License v2.1
3.44k stars 1.75k forks source link

Trivial: fix 2 warnings #64

Closed oldfaber closed 12 years ago

oldfaber commented 12 years ago

The Microsoft C compiler gives two warnings fixed using the following patch.

Regards Fabio

--- stephane-libmodbus-2dca042/src/modbus-data.c    2012-05-28 17:00:22.000000000 +0200
+++ p1-libmodbus/src/modbus-data.c  2012-06-06 17:24:39.217130000 +0200
@@ -44,7 +44,7 @@ void modbus_set_bits_from_bytes(uint8_t 
     int i;
     int shift = 0;

-    for (i = index; i < index + nb_bits; i++) {
+    for (i = index; i < index + (int)nb_bits; i++) {
         dest[i] = tab_byte[(i - index) / 8] & (1 << shift) ? 1 : 0;
         /* gcc doesn't like: shift = (++shift) % 8; */
         shift++;
@@ -57,7 +57,7 @@ void modbus_set_bits_from_bytes(uint8_t 
 uint8_t modbus_get_byte_from_bits(const uint8_t *src, int index,
                                   unsigned int nb_bits)
 {
-    int i;
+    unsigned int i;
     uint8_t value = 0;

     if (nb_bits > 8) {
stephane commented 12 years ago

Thank you for the report, I've avoided the cast, could you check master to be sure?

oldfaber commented 12 years ago

Thanks, this is a logical alternative solution. (avoids the cast, but assignes an int to an unsigned int). I'll check tomorrow if the warnings are gone.