net.c, pdu.h: ensure that valid transaction ids are positive

The calculation of transaction ids did not ensure that the result
is always greater or equal zero. To avoid conflicts with the error
codes returned by coap_send(), the calculation now masks out the
lower half.
This commit is contained in:
Olaf Bergmann committed 2015-06-10 17:46:53 +02:00
1 parent 83a06c7969
commit 3c84f5c012
2 files changed
+8 -3

No files matched your search

+7 -2
View File
@@ -155,9 +155,14 @@ char *coap_response_phrase(unsigned char code);
* use an unallocated type here and hope for the best. */
#define COAP_MEDIATYPE_ANY 0xff /* any media type */
/* CoAP transaction id */
/*typedef unsigned short coap_tid_t; */
/**
* coap_tid_t is used to store CoAP transaction id, i.e. a hash value
* built from the remote transport address and the message id of a
* CoAP PDU. Valid transaction ids are greater or equal zero.
*/
typedef int coap_tid_t;
/** Indicates an invalid transaction id. */
#define COAP_INVALID_TID -1
#ifdef WORDS_BIGENDIAN
+1 -1
View File
@@ -523,7 +523,7 @@ coap_transaction_id(const coap_address_t *peer, const coap_pdu_t *pdu,
coap_hash((const unsigned char *)&pdu->hdr->id, sizeof(unsigned short), h);
*id = ((h[0] << 8) | h[1]) ^ ((h[2] << 8) | h[3]);
*id = (((h[0] << 8) | h[1]) ^ ((h[2] << 8) | h[3])) & INT_MAX;
}
coap_tid_t