mirror of
https://github.com/merbanan/rtl_433.git
synced 2026-04-18 00:26:56 -04:00
Fix overflow warnings from static analysis (#1183)
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user