darconeous / libnyoci

A flexible CoAP stack for embedded devices and computers. RFC7252 compatible.
Other
27 stars 10 forks source link

nyoci_outbound_append_content_formatted sets incorrect length #3

Closed snej closed 6 years ago

snej commented 6 years ago

In nyoci_outbound_append_content_formatted(), the variable fmtlen is updated but unused:

    fmtlen += self->outbound.content_len;
    ret = nyoci_outbound_set_content_len((coap_size_t)len);
bail:
    va_end(args);
    return ret;
}
/Couchbase/Embedded/libnyoci/src/libnyoci/nyoci-outbound.c:647:2: warning: Value stored to 'fmtlen' is never read
        fmtlen += self->outbound.content_len;
        ^         ~~~~~~~~~~~~~~~~~~~~~~~~~~

I was going to ignore this compiler warning, but then I looked at the code, and it seems like the parameter to nyoci_outbound_set_content_len() should be fmtlen, not len -- the latter is just the space remaining in the packet, while fmtlen is the previous content_len plus the number of bytes written by vsnprintf.

darconeous commented 6 years ago

Good catch!