From 76271e1cbfe0be0196503718ff463fd64e42f24b Mon Sep 17 00:00:00 2001 From: Olaf Bergmann Date: Wed, 2 Nov 2011 17:20:50 +0100 Subject: [PATCH] fixed type conversions (thanks to Philippe Valembois for pointing this out) --- Makefile.in | 2 +- bits.h | 4 ++-- debug.c | 4 ++-- debug.h | 2 +- net.c | 8 ++++++-- resource.h | 2 +- 6 files changed, 13 insertions(+), 9 deletions(-) diff --git a/Makefile.in b/Makefile.in index 852df117..5163a6bc 100644 --- a/Makefile.in +++ b/Makefile.in @@ -24,7 +24,7 @@ SOURCES:= pdu.c net.c debug.c encode.c uri.c list.c resource.c hashkey.c \ OBJECTS:= $(patsubst %.c, %.o, $(SOURCES)) HEADERS:=coap.h config.h debug.h pdu.h net.h encode.h uri.h list.h mem.h \ str.h option.h bits.h uthash.h utlist.h resource.h hashkey.h async.h -CFLAGS:=-Wall -std=c99 -pedantic @CFLAGS@ +CFLAGS:=-Wall -Wextra -std=c99 -pedantic @CFLAGS@ CPPFLAGS:=@CPPFLAGS@ DISTDIR=$(top_builddir)/$(package) SUBDIRS:=examples doc diff --git a/bits.h b/bits.h index 9224aa77..0121b97f 100644 --- a/bits.h +++ b/bits.h @@ -33,7 +33,7 @@ bits_setb(uint8_t *vec, size_t size, uint8_t bit) { if (size <= (bit >> 3)) return -1; - *(vec + (bit >> 3)) |= 1 << (bit & 0x07); + *(vec + (bit >> 3)) |= (uint8_t)(1 << (bit & 0x07)); return 1; } @@ -53,7 +53,7 @@ bits_clrb(uint8_t *vec, size_t size, uint8_t bit) { if (size <= (bit >> 3)) return -1; - *(vec + (bit >> 3)) &= ~(1 << (bit & 0x07)); + *(vec + (bit >> 3)) &= (uint8_t)(~(1 << (bit & 0x07))); return 1; } diff --git a/debug.c b/debug.c index 39de6837..52a340ba 100644 --- a/debug.c +++ b/debug.c @@ -199,7 +199,7 @@ coap_show_pdu(const coap_pdu_t *pdu) { #endif /* NDEBUG */ void -coap_log_impl(coap_log_t level, char *format, ...) { +coap_log_impl(coap_log_t level, const char *format, ...) { char timebuf[32]; coap_tick_t now; va_list ap; @@ -220,5 +220,5 @@ coap_log_impl(coap_log_t level, char *format, ...) { va_start(ap, format); vfprintf(log_fd, format, ap); va_end(ap); - fflush(stdout); + fflush(log_fd); } diff --git a/debug.h b/debug.h index d5f230ae..17c6d1a8 100644 --- a/debug.h +++ b/debug.h @@ -34,7 +34,7 @@ void coap_set_log_level(coap_log_t level); * text is output only when @p level is below or equal to the log * level that set by coap_set_log_level(). */ -void coap_log_impl(coap_log_t level, char *format, ...); +void coap_log_impl(coap_log_t level, const char *format, ...); #ifndef coap_log #define coap_log(...) coap_log_impl(__VA_ARGS__) diff --git a/net.c b/net.c index ee241480..51e0d2ac 100644 --- a/net.c +++ b/net.c @@ -424,7 +424,7 @@ coap_read( coap_context_t *ctx ) { return -1; } - if ( bytes_read < sizeof(coap_hdr_t) ) { + if ( (size_t)bytes_read < sizeof(coap_hdr_t) ) { debug("coap_read: discarded invalid frame\n" ); return -1; } @@ -757,9 +757,13 @@ handle_response(coap_context_t *context, } } - static inline int +#ifdef __GNUC__ +handle_locally(coap_context_t *context __attribute__ ((unused)), + coap_queue_t *node __attribute__ ((unused))) { +#else /* not a GCC */ handle_locally(coap_context_t *context, coap_queue_t *node) { +#endif /* GCC */ /* this function can be used to check if node->pdu is really for us */ return 1; } diff --git a/resource.h b/resource.h index 51f952c0..109baeb6 100644 --- a/resource.h +++ b/resource.h @@ -158,7 +158,7 @@ static inline void coap_register_handler(coap_resource_t *resource, unsigned char method, coap_method_handler_t handler) { assert(resource); - assert(method-1 < sizeof(coap_method_handler_t)); + assert(method > 0 && (size_t)(method-1) < sizeof(resource->handler)/sizeof(coap_method_handler_t)); resource->handler[method-1] = handler; }