From f4ab51bf16c5d6bd70c4a9d4b7b29a88e2d66bbc Mon Sep 17 00:00:00 2001 From: Erich Keane Date: Mon, 15 Sep 2014 14:15:43 -0700 Subject: [PATCH] Fixing a few warnings that we see coming out of the libcoap bits.h file. Essentially, the result of the bit-shift on a uint8_t is always upconverted to a signed int despite it being impossible for it to be anything greater than 5 bits long (8 bits, shifted 3 more). We cast to unsigned size_t to prevent the warning and to prevent unsigned vs signed comparison. Change-Id: I47d05611e75e55240b55b800c9370dbc019aedd2 --- csdk/libcoap-4.1.1/bits.h | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/csdk/libcoap-4.1.1/bits.h b/csdk/libcoap-4.1.1/bits.h index c8d7bda..22c0b62 100644 --- a/csdk/libcoap-4.1.1/bits.h +++ b/csdk/libcoap-4.1.1/bits.h @@ -4,7 +4,7 @@ * Copyright (C) 2010,2011 Olaf Bergmann * * This file is part of the CoAP library libcoap. Please see - * README for terms of use. + * README for terms of use. */ /** @@ -24,59 +24,59 @@ extern "C" { #endif #include -/** +/** * Sets the bit @p bit in bit-vector @p vec. This function returns @c * 1 if bit was set or @c -1 on error (i.e. when the given bit does * not fit in the vector). - * + * * @param vec The bit-vector to change. * @param size The size of @p vec in bytes. * @param bit The bit to set in @p vec. - * + * * @return @c -1 if @p bit does not fit into @p vec, @c 1 otherwise. */ inline static int bits_setb(uint8_t *vec, size_t size, uint8_t bit) { - if (size <= (bit >> 3)) + if (size <= (size_t)(bit >> 3)) return -1; *(vec + (bit >> 3)) |= (uint8_t)(1 << (bit & 0x07)); return 1; } -/** +/** * Clears the bit @p bit from bit-vector @p vec. This function returns * @c 1 if bit was cleared or @c -1 on error (i.e. when the given bit * does not fit in the vector). - * + * * @param vec The bit-vector to change. * @param size The size of @p vec in bytes. * @param bit The bit to clear from @p vec. - * + * * @return @c -1 if @p bit does not fit into @p vec, @c 1 otherwise. */ inline static int bits_clrb(uint8_t *vec, size_t size, uint8_t bit) { - if (size <= (bit >> 3)) + if (size <= (size_t)(bit >> 3)) return -1; *(vec + (bit >> 3)) &= (uint8_t)(~(1 << (bit & 0x07))); return 1; } -/** +/** * Gets the status of bit @p bit from bit-vector @p vec. This function returns * @c 1 if the bit is set, @c 0 otherwise (even in case of an error).. - * + * * @param vec The bit-vector to read from.. * @param size The size of @p vec in bytes. * @param bit The bit to get from @p vec. - * + * * @return @c 1 if the bit is set, @c 0 otherwise. */ inline static int bits_getb(const uint8_t *vec, size_t size, uint8_t bit) { - if (size <= (bit >> 3)) + if (size <= (size_t)(bit >> 3)) return -1; return (*(vec + (bit >> 3)) & (1 << (bit & 0x07))) != 0; -- 2.7.4