eclipse / paho.mqtt-sn.embedded-c

Paho C MQTT-SN gateway and libraries for embedded systems. Paho is an Eclipse IoT project.
https://eclipse.org/paho
Other
314 stars 179 forks source link

Suspicious code in MQTTSNGWPacket.cpp #219

Closed osaether closed 3 years ago

osaether commented 3 years ago

Setting buf to _buf in this function in MQTTSNGWPacket.cpp has no effect:

int MQTTSNPacket::serialize(uint8_t* buf)
{
    buf = _buf;
    return _bufLen;
}
ty4tw commented 3 years ago

Hi, Serialize method returns serialized data and it’s length. it’s not suspicious code.

osaether commented 3 years ago

Hi, Serialize method returns serialized data and it’s length. it’s not suspicious code.

You are setting the local pointer "buf" to "_buf" but "buf" is not returned from the function. If you want to change what "buf" points to you could use memcpy or something.

ty4tw commented 3 years ago

int MQTTSNPacket::serialize(uint8_t* buf) is a getter method, not a setter method.

but "buf" is not returned from the function.

You can get serialized data via uint8_t buf value setten by this method. (uint8_t buf is a same as uint8_t *buf.)