From: Petteri Aimonen Date: Fri, 9 Dec 2016 16:57:08 +0000 (+0200) Subject: Enable clang integer sanitizer and clean up a few warnings. X-Git-Tag: 5.0.2~186^2~38 X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=commitdiff_plain;h=58af4d1fb733c5348b68dd3980f2a230d95400b4;p=apps%2Fagl-service-can-low-level.git 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. --- diff --git a/pb_decode.c b/pb_decode.c index 1f6aeae0..b2a3a310 100644 --- a/pb_decode.c +++ b/pb_decode.c @@ -75,13 +75,14 @@ static const pb_decoder_t PB_DECODERS[PB_LTYPES_COUNT] = { static bool checkreturn buf_read(pb_istream_t *stream, pb_byte_t *buf, size_t count) { + size_t i; const pb_byte_t *source = (const pb_byte_t*)stream->state; stream->state = (pb_byte_t*)stream->state + count; if (buf != NULL) { - while (count--) - *buf++ = *source++; + for (i = 0; i < count; i++) + buf[i] = source[i]; } return true; diff --git a/pb_encode.c b/pb_encode.c index 13bda22c..cafe853c 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; } diff --git a/tests/SConstruct b/tests/SConstruct index f2abe042..ae79f710 100644 --- a/tests/SConstruct +++ b/tests/SConstruct @@ -95,7 +95,7 @@ if not env.GetOption('clean'): # Check if we can use undefined behaviour sanitizer (only with clang) # TODO: Fuzz test triggers the bool sanitizer, figure out whether to # modify the fuzz test or to keep ignoring the check. - extra = '-fsanitize=undefined -fno-sanitize-recover=undefined -fsanitize-recover=bool ' + extra = '-fsanitize=undefined,integer -fno-sanitize-recover=undefined,integer -fsanitize-recover=bool ' if 'clang' in env['CC']: if conf.CheckCCFLAGS(extra, linkflags = extra): conf.env.Append(CORECFLAGS = extra)