eclipse/paho.mqtt.c

readInt in MQTTPacket.c returns badness

december1981 opened this issue · 3 comments

This fixed it for me. Otherwise, what should return, say, 128 ends up returning -128, because of anomolous sign extension from the lower byte of the integer.

--- a/src/MQTTPacket.c
+++ b/src/MQTTPacket.c
@@ -362,7 +362,7 @@ exit:
 int readInt(char** pptr)
 {
        char *ptr = *pptr;
-       int val = ((((uint32_t)ptr[0]) << 8) | ((uint32_t)ptr[1]));
+       int val = ((((uint32_t)ptr[0]) << 8) | (uint8_t)ptr[1]);
        *pptr += 2;
        return val;
 }

Thanks.

Ref: #1327. I may revert that change and put my own in.

I've reverted that PR, so hopefully should work now.

Then I'll close this