Fix some warnings from static analysis ()

This commit is contained in:
Christian W. Zuckschwerdt 2019-10-29 12:42:42 +01:00
parent d03c710e85
commit ca440974c9
13 changed files with 30 additions and 23 deletions

View file

@ -58,9 +58,8 @@ int abuf_printf(abuf_t *buf, const char *restrict format, ...)
int n = vsnprintf(buf->tail, buf->left, format, ap);
size_t len = 0;
if (n > 0) {
len = (size_t)n < buf->left ? (size_t)n : buf->left;
size_t len = (size_t)n < buf->left ? (size_t)n : buf->left;
buf->tail += len;
buf->left -= len;
}

View file

@ -87,7 +87,7 @@ void am_analyze(am_analyze_t *a, int16_t *am_buf, unsigned n_samples, int debug_
unsigned padded_start = a->signal_start - FRAME_PAD;
unsigned padded_end = a->counter - FRAME_END_MIN + FRAME_PAD;
unsigned padded_len = padded_end - padded_start;
fprintf(stderr, "*** signal_start = %d, signal_end = %d, signal_len = %d, pulses_found = %d\n",
fprintf(stderr, "*** signal_start = %u, signal_end = %u, signal_len = %u, pulses_found = %u\n",
padded_start, padded_end, padded_len, a->pulses_found);
am_analyze_classify(a); // clears signal_pulse_data
@ -106,7 +106,7 @@ void am_analyze(am_analyze_t *a, int16_t *am_buf, unsigned n_samples, int debug_
void am_analyze_classify(am_analyze_t *aa)
{
unsigned int i, k, max = 0, min = 1000000, t;
unsigned int delta, count_min, count_max, min_new, max_new, p_limit;
unsigned int delta, p_limit;
unsigned int a[3], b[2], a_cnt[3], a_new[3];
unsigned int signal_distance_data[PULSE_DATA_SIZE] = {0};
bitbuffer_t bits = {0};
@ -134,10 +134,10 @@ void am_analyze_classify(am_analyze_t *aa)
//TODO use Lloyd-Max quantizer instead
k = 1;
while ((k < 10) && (delta > 0)) {
min_new = 0;
count_min = 0;
max_new = 0;
count_max = 0;
unsigned min_new = 0;
unsigned count_min = 0;
unsigned max_new = 0;
unsigned count_max = 0;
for (i = 0; i < aa->signal_pulse_counter; i++) {
if (aa->signal_pulse_data[i][0] > 0) {
@ -160,7 +160,7 @@ void am_analyze_classify(am_analyze_t *aa)
max = max_new;
t = (min + max) / 2;
fprintf(stderr, "Iteration %d. t: %d min: %d (%d) max: %d (%d) delta %d\n", k, t, min, count_min, max, count_max, delta);
fprintf(stderr, "Iteration %u. t: %u min: %u (%u) max: %u (%u) delta %u\n", k, t, min, count_min, max, count_max, delta);
k++;
}

View file

@ -249,7 +249,7 @@ static void print_bitrow(bitrow_t const bitrow, unsigned bit_len, unsigned highe
{
unsigned row_len = 0;
fprintf(stderr, "{%2d} ", bit_len);
fprintf(stderr, "{%2u} ", bit_len);
for (unsigned col = 0; col < (bit_len + 7) / 8; ++col) {
row_len += fprintf(stderr, "%02x ", bitrow[col]);
}
@ -289,7 +289,7 @@ static void print_bitbuffer(const bitbuffer_t *bits, int always_binary)
fprintf(stderr, "bitbuffer:: Number of rows: %d \n", bits->num_rows);
for (row = 0; row < bits->num_rows; ++row) {
fprintf(stderr, "[%02d] ", row);
fprintf(stderr, "[%02u] ", row);
print_bitrow(bits->bb[row], bits->bits_per_row[row], highest_indent, always_binary);
}
if (bits->num_rows >= BITBUF_ROWS) {

View file

@ -198,7 +198,7 @@ static data_t *vdata_make(data_t *first, const char *key, const char *pretty_key
data_t *prev = first;
while (prev && prev->next)
prev = prev->next;
char *format = false;
char *format = NULL;
type = va_arg(ap, data_type_t);
do {
data_t *current;

View file

@ -145,7 +145,7 @@ static char *bitrow_asprint_code(bitrow_t const bitrow, unsigned bit_len)
WARN_MALLOC("decoder_output_bitbuffer()");
return NULL; // NOTE: returns NULL on alloc failure.
}
sprintf(row_code, "{%d}%s", bit_len, row_bytes);
sprintf(row_code, "{%u}%s", bit_len, row_bytes);
return row_code;
}

View file

@ -299,7 +299,7 @@ static int directv_decode(r_device *decoder, bitbuffer_t *bitbuffer)
if ((bit_len < ROW_BITLEN_MIN) || (bit_len > ROW_BITLEN_MAX)) {
if (decoder->verbose >= 2) {
fprintf(stderr, "directv: incorrect number of bits in bitbuffer: %u (expected between %u and %u).\n", bit_len, ROW_BITLEN_MIN, ROW_BITLEN_MAX);
fprintf(stderr, "directv: incorrect number of bits in bitbuffer: %d (expected between %d and %d).\n", bit_len, ROW_BITLEN_MIN, ROW_BITLEN_MAX);
}
return 0;
}

View file

@ -163,9 +163,9 @@ static int ws2000_callback(r_device *decoder, bitbuffer_t *bitbuffer)
return 0;
}
char *subtype = dec[0] <= 7 ? types[dec[0]] : "?";
char *subtype = (dec[0] <= 7) ? types[dec[0]] : "?";
int code = dec[1] & 7;
float temp = (dec[1] & 8 ? -1.0 : 1.0) * (dec[4] * 10 + dec[3] + dec[2] * 0.1);
float temp = ((dec[1] & 8) ? -1.0 : 1.0) * (dec[4] * 10 + dec[3] + dec[2] * 0.1);
float humidity = dec[7] * 10 + dec[6] + dec[5] * 0.1;
int pressure = 0;
if (dec[0]==4) {

View file

@ -95,7 +95,7 @@ static int lacrosse_ws7000_decode(r_device *decoder, bitbuffer_t *bitbuffer)
if (type == 0) {
// 0 = WS7000-27/28 Thermo sensor
int sign = b[1] & 0x8 ? -1 : 1;
int sign = (b[1] & 0x8) ? -1 : 1;
float temperature = ((b[4] * 10) + (b[3] * 1) + (b[2] * 0.1)) * sign;
/* clang-format off */
@ -113,7 +113,7 @@ static int lacrosse_ws7000_decode(r_device *decoder, bitbuffer_t *bitbuffer)
}
else if (type == 1) {
// 1 = WS7000-22/25 Thermo/Humidity sensor
int sign = b[1] & 0x8 ? -1 : 1;
int sign = (b[1] & 0x8) ? -1 : 1;
float temperature = ((b[4] * 10) + (b[3] * 1) + (b[2] * 0.1)) * sign;
int humidity = (b[7] * 10) + (b[6] * 1) + (b[5] * 0.1);
@ -171,7 +171,7 @@ static int lacrosse_ws7000_decode(r_device *decoder, bitbuffer_t *bitbuffer)
}
else if (type == 4) {
// 4 = WS7000-20 Thermo/Humidity/Barometer sensor
int sign = b[1] & 0x8 ? -1 : 1;
int sign = (b[1] & 0x8) ? -1 : 1;
float temperature = ((b[4] * 10) + (b[3] * 1) + (b[2] * 0.1)) * sign;
int humidity = (b[7] * 10) + (b[6] * 1) + (b[5] * 0.1);
int pressure = (b[10] * 100) + (b[9] * 10) + (b[8] * 1) + 200;

View file

@ -123,7 +123,7 @@ static int philips_aj3650_decode(r_device *decoder, bitbuffer_t *bitbuffer)
/* Channel */
channel = packet[0] & 0x0f;
if (channel > (sizeof(channel_map) / sizeof(channel_map[0])))
if (channel >= (sizeof(channel_map) / sizeof(channel_map[0])))
channel = 0;
else
channel = channel_map[channel];

View file

@ -110,7 +110,7 @@ static int philips_aj7010_decode(r_device *decoder, bitbuffer_t *bitbuffer)
temp_raw = ((b[3] & 0x3f) << 8) | b[2];
temp_c = (temp_raw / 353.0) - 9.2; // TODO: this is very likely wrong
if (decoder->verbose) {
fprintf(stderr, "\ntemperature: raw: %u\t%08X\tconverted: %.2f\n", temp_raw, temp_raw, temp_c);
fprintf(stderr, "\ntemperature: raw: %d\t%08X\tconverted: %.2f\n", temp_raw, temp_raw, temp_c);
}
/* clang-format off */

View file

@ -110,7 +110,6 @@ static uint32_t file_type_guess_auto_format(uint32_t type)
else if (type == F_CS8) return CS8_IQ;
else if (type == F_S16) return S16_AM;
else if (type == F_U8) return U8_LOGIC;
else if (type == F_Q) return F32_Q;
else if (type == F_VCD) return VCD_LOGIC;
else if (type == F_OOK) return PULSE_OOK;
else if (type == F_CS16) return CS16_IQ;

View file

@ -438,6 +438,7 @@ static void data_output_mqtt_free(data_output_t *output)
static char *mqtt_topic_default(char const *topic, char const *base, char const *suffix)
{
char path[256];
char const *p;
if (topic) {
p = topic;
@ -446,7 +447,6 @@ static char *mqtt_topic_default(char const *topic, char const *base, char const
p = suffix;
}
else {
char path[256];
snprintf(path, sizeof(path), "%s/%s", base, suffix);
p = path;
}

View file

@ -162,4 +162,13 @@ int main(int argc, char *argv[])
baseband_demod_FM_cs16(cs16_buf, s16_buf, n_samples, &fm_state);
);
write_buf("bb.cs16.fm.s16", s16_buf, sizeof(int16_t) * n_samples);
free(cu8_buf);
free(y16_buf);
free(cs16_buf);
free(y32_buf);
free(u16_buf);
free(u32_buf);
free(s16_buf);
free(s32_buf);
}