From 58af4d1fb733c5348b68dd3980f2a230d95400b4 Mon Sep 17 00:00:00 2001 From: Petteri Aimonen Date: Fri, 9 Dec 2016 18:57:08 +0200 Subject: Enable clang integer sanitizer and clean up a few warnings. Changed to use simple indexing instead of while (count--) in buf_read()/buf_write(), because the count overflowed from 0 to max on the last iteration. While the unsigned integer overflow is defined and behaviour was correct, making this simple change allowed enabling the sanitizer which might catch true errors elsewhere in the code. --- pb_encode.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'pb_encode.c') diff --git a/pb_encode.c b/pb_encode.c index 13bda22..cafe853 100644 --- a/pb_encode.c +++ b/pb_encode.c @@ -59,11 +59,12 @@ static const pb_encoder_t PB_ENCODERS[PB_LTYPES_COUNT] = { static bool checkreturn buf_write(pb_ostream_t *stream, const pb_byte_t *buf, size_t count) { + size_t i; pb_byte_t *dest = (pb_byte_t*)stream->state; stream->state = dest + count; - while (count--) - *dest++ = *buf++; + for (i = 0; i < count; i++) + dest[i] = buf[i]; return true; } -- cgit v1.2.3