From b785a67293a99d330c6be9c822bc150c421b26de Mon Sep 17 00:00:00 2001 From: "Christian W. Zuckschwerdt" Date: Wed, 30 Oct 2019 09:31:29 +0100 Subject: [PATCH] Fix overflow warnings from static analysis (#1183) --- include/bitbuffer.h | 4 ++-- src/baseband.c | 4 ++-- src/bitbuffer.c | 6 +++--- src/data.c | 2 +- src/r_util.c | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/include/bitbuffer.h b/include/bitbuffer.h index 0b43732a..c6eea368 100644 --- a/include/bitbuffer.h +++ b/include/bitbuffer.h @@ -63,10 +63,10 @@ void bitbuffer_print(const bitbuffer_t *bits); void bitbuffer_debug(const bitbuffer_t *bits); /// Print the content of a bit row (byte buffer). -void bitrow_print(bitrow_t const bitrow, unsigned bit_len); +void bitrow_print(uint8_t const *bitrow, unsigned bit_len); /// Debug the content of a bit row (byte buffer). -void bitrow_debug(bitrow_t const bitrow, unsigned bit_len); +void bitrow_debug(uint8_t const *bitrow, unsigned bit_len); /// Parse a string into a bitbuffer. void bitbuffer_parse(bitbuffer_t *bits, const char *code); diff --git a/src/baseband.c b/src/baseband.c index ac1734c5..dfcf48cc 100644 --- a/src/baseband.c +++ b/src/baseband.c @@ -272,8 +272,8 @@ void baseband_demod_FM_cs16(int16_t const *x_buf, int16_t *y_buf, unsigned long ar = x_buf[2*n]; ai = x_buf[2*n+1]; // Calculate phase difference vector: x[n] * conj(x[n-1]) - pr = (int64_t)ar*br+ai*bi; // May exactly overflow an int32_t (-32768*-32768 + -32768*-32768) - pi = (int64_t)ai*br-ar*bi; + pr = (int64_t)ar*br + (int64_t)ai*bi; // May exactly overflow an int32_t (-32768*-32768 + -32768*-32768) + pi = (int64_t)ai*br - (int64_t)ar*bi; // xlp = (int32_t)((atan2f(pi, pr) / M_PI) * INT32_MAX); // Floating point implementation xlp = atan2_int32(pi, pr); // Integer implementation // xlp = atan2_int16(pi>>16, pr>>16) << 16; // Integer implementation diff --git a/src/bitbuffer.c b/src/bitbuffer.c index 486966e2..dc5447fa 100644 --- a/src/bitbuffer.c +++ b/src/bitbuffer.c @@ -245,7 +245,7 @@ unsigned bitbuffer_differential_manchester_decode(bitbuffer_t *inbuf, unsigned r return ipos; } -static void print_bitrow(bitrow_t const bitrow, unsigned bit_len, unsigned highest_indent, int always_binary) +static void print_bitrow(uint8_t const *bitrow, unsigned bit_len, unsigned highest_indent, int always_binary) { unsigned row_len = 0; @@ -307,12 +307,12 @@ void bitbuffer_debug(const bitbuffer_t *bits) print_bitbuffer(bits, 1); } -void bitrow_print(bitrow_t const bitrow, unsigned bit_len) +void bitrow_print(uint8_t const *bitrow, unsigned bit_len) { print_bitrow(bitrow, bit_len, 0, 0); } -void bitrow_debug(bitrow_t const bitrow, unsigned bit_len) +void bitrow_debug(uint8_t const *bitrow, unsigned bit_len) { print_bitrow(bitrow, bit_len, 0, 1); } diff --git a/src/data.c b/src/data.c index 186199f1..ff994554 100644 --- a/src/data.c +++ b/src/data.c @@ -156,7 +156,7 @@ static bool import_values(void *dst, void *src, int num_values, data_type_t type } } } else { - memcpy(dst, src, element_size * num_values); + memcpy(dst, src, (size_t)element_size * num_values); } return true; // error is returned early } diff --git a/src/r_util.c b/src/r_util.c index 5541c428..bd899d7e 100644 --- a/src/r_util.c +++ b/src/r_util.c @@ -169,7 +169,7 @@ char *str_replace(char const *orig, char const *rep, char const *with) ins = tmp + len_rep; } - tmp = result = malloc(strlen(orig) + (len_with - len_rep) * count + 1); + tmp = result = malloc(strlen(orig) + (len_with - len_rep) * (size_t)count + 1); if (!result) { WARN_MALLOC("str_replace()"); return NULL; // NOTE: returns NULL on alloc failure.