X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=src%2Fpackmsg.h;h=69632f518578d3e67c63ede9617c373150fbf6ac;hb=HEAD;hp=a145722df79b646e2bc2442cca42f989483f0e8f;hpb=fe5563f92021618b4a8b41e412c73d8364fcaf6e;p=meshlink diff --git a/src/packmsg.h b/src/packmsg.h index a145722d..675011e2 100644 --- a/src/packmsg.h +++ b/src/packmsg.h @@ -129,7 +129,7 @@ typedef struct packmsg_input { * \memberof packmsg_output * * This function checks if all operations performed on the output buffer so far - * have all completed succesfully, and the buffer contains a valid PackMessage message. + * have all completed successfully, and the buffer contains a valid PackMessage message. * * \param buf A pointer to an output buffer iterator. * @@ -166,7 +166,7 @@ static inline size_t packmsg_output_size(const packmsg_output_t *buf, const uint * \memberof packmsg_input * * This function checks if all operations performed on the input buffer so far - * have all completed succesfully, and the buffer contains a valid PackMessage message. + * have all completed successfully, and the buffer contains a valid PackMessage message. * * \param buf A pointer to an input buffer iterator. * @@ -250,7 +250,7 @@ static inline void packmsg_write_data_(packmsg_output_t *buf, const void *data, assert(buf->ptr); assert(data); - if(packmsg_likely(buf->len >= dlen)) { + if(packmsg_likely(buf->len >= 0 && (uint32_t)buf->len >= dlen)) { memcpy(buf->ptr, data, dlen); buf->ptr += dlen; buf->len -= dlen; @@ -265,7 +265,7 @@ static inline void packmsg_write_hdrdata_(packmsg_output_t *buf, uint8_t hdr, co assert(buf->ptr); assert(data); - if(packmsg_likely(buf->len > dlen)) { + if(packmsg_likely(buf->len > 0 && (uint32_t)buf->len > dlen)) { *buf->ptr = hdr; buf->ptr++; buf->len--; @@ -283,7 +283,7 @@ static inline void *packmsg_reserve_(packmsg_output_t *buf, uint32_t len) { assert(buf); assert(buf->ptr); - if(packmsg_likely(buf->len >= len)) { + if(packmsg_likely(buf->len >= 0 && (uint32_t)buf->len >= len)) { void *ptr = buf->ptr; buf->ptr += len; buf->len -= len; @@ -706,7 +706,7 @@ static inline void packmsg_read_data_(packmsg_input_t *buf, void *data, uint32_t assert(buf->ptr); assert(data); - if(packmsg_likely(buf->len >= dlen)) { + if(packmsg_likely(buf->len >= 0 && (uint32_t)buf->len >= dlen)) { memcpy(data, buf->ptr, dlen); buf->ptr += dlen; buf->len -= dlen; @@ -730,8 +730,8 @@ static inline uint8_t packmsg_peek_hdr_(const packmsg_input_t *buf) { /** \brief Get a NIL from the input. * \memberof packmsg_input * - * This function does not return anything, but will invalidate the input interator - * if no NIL was succesfully consumed from the input. + * This function does not return anything, but will invalidate the input iterator + * if no NIL was successfully consumed from the input. * * \param buf A pointer to an input buffer iterator. */ @@ -1047,7 +1047,7 @@ static inline uint32_t packmsg_get_str_raw(packmsg_input_t *buf, const char **st return 0; } - if(packmsg_likely(buf->len >= slen)) { + if(packmsg_likely(buf->len >= 0 && (uint32_t)buf->len >= slen)) { *str = (const char *)buf->ptr; buf->ptr += slen; buf->len -= slen; @@ -1096,7 +1096,7 @@ static inline char *packmsg_get_str_dup(packmsg_input_t *buf) { * * This function copies a string from the input another buffer provided by the application. * The buffer must be long enough to hold the complete string plus a terminating NUL-byte. - * If the buffer is not long enough, or another error occured, + * If the buffer is not long enough, or another error occurred, * a single NUL-byte will be written to the start of the buffer (if its size is at least one byte). * * \param buf A pointer to an input buffer iterator. @@ -1165,7 +1165,7 @@ static inline uint32_t packmsg_get_bin_raw(packmsg_input_t *buf, const void **da return 0; } - if(packmsg_likely(buf->len >= dlen)) { + if(packmsg_likely(buf->len >= 0 && (uint32_t)buf->len >= dlen)) { *data = buf->ptr; buf->ptr += dlen; buf->len -= dlen; @@ -1283,7 +1283,7 @@ static inline uint32_t packmsg_get_ext_raw(packmsg_input_t *buf, int8_t *type, c *type = packmsg_read_hdr_(buf); - if(packmsg_likely(buf->len >= dlen)) { + if(packmsg_likely(buf->len >= 0 && (uint32_t)buf->len >= dlen)) { *data = buf->ptr; buf->ptr += dlen; buf->len -= dlen; @@ -1444,8 +1444,8 @@ static inline uint32_t packmsg_get_array(packmsg_input_t *buf) { * * This enum describes the type of an element in a PackMessage message. * In case of integers and floating point values, the type normally represents - * the smallest type that can succesfully hold the value of the element; - * i.e. an element of type PACKMSG_INT32 can only succesfully be read by + * the smallest type that can successfully hold the value of the element; + * i.e. an element of type PACKMSG_INT32 can only successfully be read by * packmsg_get_int32() or packmsg_get_int64(). However, the converse it not true; * for an element of type PACKMSG_INT32, there is no guarantee * that the value is larger than would fit into an int16_t. @@ -2002,7 +2002,7 @@ static inline void packmsg_skip_element(packmsg_input_t *buf) { dlen = skip; } - if(packmsg_likely(buf->len >= dlen)) { + if(packmsg_likely(buf->len >= 0 && (uint32_t)buf->len >= dlen)) { buf->ptr += dlen; buf->len -= dlen; } else {