staropram / cantcoap

CoAP implementation that focuses on simplicity by offering a minimal set of functions and straightforward interface.
BSD 2-Clause "Simplified" License
86 stars 38 forks source link

Option adding to fresh pdu seems broken #13

Closed sdrsdr closed 8 years ago

sdrsdr commented 8 years ago

Consider this sample code:

CoapPDU pdu;
pdu.setType(CoapPDU::COAP_ACKNOWLEDGEMENT);
pdu.setMessageID(0x1234);
pdu->setCode(CoapPDU::COAP_CONTENT);
pdu.printHuman();
pdu.addOption(3828,17,"12345678901234567");
pdu.printHuman();

The second pdu.printHuman() is producing total garbage. as a side note, pdu.printHuman() will quit if no options are present, not showing the payload.

staropram commented 8 years ago

Thanks, this is a bug. I didn't use 2 byte option codes so I never tested them... Will merge your fixes in soon. I just noticed that there is also a problem with out-of-order insertion for 2 byte option codes, so I'll make the fix for that first.