paho.mqtt.embedded-c icon indicating copy to clipboard operation
paho.mqtt.embedded-c copied to clipboard

fix publish return err

Open sundaylee opened this issue 5 years ago • 1 comments

Fixed segmentation error during data processing due to incorrect browser return value

sundaylee avatar Aug 15 '19 07:08 sundaylee

Well, that is a too broad, misleading, and perhaps incorrect description. What I think I see (perhaps I'm not seeing what you see) is that in the event that not enough characters are received, rc in line 53 gets the number of chars decoded and so this trashes what otherwise would have been a correct return code (initialized in line 42). That, when returned, causes another function to fail and then somehow something breaks in your code and you see a segmentation error. (Many of us don't run this on an OS and we can't see segmentation errors, btw)

To me, a more appropriate way to fix this is to eliminate rc in line 53: curdata += (rc = MQTTPacket_decodeBuf(curdata, &mylen)); /* read remaining length */ to curdata += MQTTPacket_decodeBuf(curdata, &mylen); /* read remaining length */ or use a different holder for return value (instead of rc) in case we need it later or want to be neat.

Am I missing something ?

scaprile avatar Aug 15 '19 12:08 scaprile