From ca84af553cbaae45b17cce04d457b2e61cc4277c Mon Sep 17 00:00:00 2001 From: Paul Selkirk Date: Mon, 23 Oct 2017 18:05:31 -0400 Subject: Cleanup signed/unsigned mismatches, mostly in loop counters --- xdr.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'xdr.c') diff --git a/xdr.c b/xdr.c index 0f172fb..e7c81b2 100644 --- a/xdr.c +++ b/xdr.c @@ -34,6 +34,7 @@ #include #include +#include /* ptrdiff_t */ #include /* 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; -- cgit v1.2.3