aboutsummaryrefslogtreecommitdiff
path: root/xdr.c
diff options
context:
space:
mode:
authorPaul Selkirk <paul@psgd.org>2017-10-23 18:05:31 -0400
committerPaul Selkirk <paul@psgd.org>2017-10-23 18:05:31 -0400
commitca84af553cbaae45b17cce04d457b2e61cc4277c (patch)
tree90f2bc5e96d2f1ae3fece3dfb9075edda08c4ace /xdr.c
parent12a3c63b75044b207dd7982ce3ed170231bd4467 (diff)
Cleanup signed/unsigned mismatches, mostly in loop counters
Diffstat (limited to 'xdr.c')
-rw-r--r--xdr.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/xdr.c b/xdr.c
index 0f172fb..e7c81b2 100644
--- a/xdr.c
+++ b/xdr.c
@@ -34,6 +34,7 @@
#include <stdio.h>
#include <stdint.h>
+#include <stddef.h> /* ptrdiff_t */
#include <string.h> /* memcpy, memset */
#include "hal.h"
@@ -52,7 +53,7 @@ hal_error_t hal_xdr_encode_int(uint8_t ** const outbuf, const uint8_t * const li
return HAL_ERROR_BAD_ARGUMENTS;
/* buffer overflow check */
- if (limit - *outbuf < sizeof(value))
+ if (limit - *outbuf < (ptrdiff_t)sizeof(value))
return HAL_ERROR_XDR_BUFFER_OVERFLOW;
**(uint32_t **)outbuf = htonl(value);
@@ -67,7 +68,7 @@ hal_error_t hal_xdr_decode_int(const uint8_t ** const inbuf, const uint8_t * con
return HAL_ERROR_BAD_ARGUMENTS;
/* buffer overflow check */
- if (limit - *inbuf < sizeof(*value))
+ if (limit - *inbuf < (ptrdiff_t)sizeof(*value))
return HAL_ERROR_XDR_BUFFER_OVERFLOW;
*value = ntohl(**(uint32_t **)inbuf);
@@ -101,7 +102,7 @@ hal_error_t hal_xdr_encode_buffer(uint8_t **outbuf, const uint8_t * const limit,
return HAL_ERROR_BAD_ARGUMENTS;
/* buffer overflow check */
- if ((limit - *outbuf) < (((len + 3) & ~3) + sizeof(len)))
+ if (limit - *outbuf < (ptrdiff_t)(((len + 3) & ~3) + sizeof(len)))
return HAL_ERROR_XDR_BUFFER_OVERFLOW;
/* encode length */
@@ -144,7 +145,7 @@ hal_error_t hal_xdr_decode_buffer_in_place(const uint8_t **inbuf, const uint8_t
/* decoded length is past the end of the input buffer;
* we're probably out of sync, but nothing we can do now
*/
- if (limit - *inbuf < xdr_len) {
+ if (limit - *inbuf < (ptrdiff_t)xdr_len) {
/* undo read of length */
*inbuf = orig_inbuf;
return HAL_ERROR_XDR_BUFFER_OVERFLOW;