Skip to content

Commit

Permalink
minor: Fix stricter compiler warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
zuckschwerdt committed Nov 13, 2021
1 parent cf05ceb commit 6c8af75
Show file tree
Hide file tree
Showing 19 changed files with 89 additions and 71 deletions.
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ if(("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_C_COMPILER_ID}" MATCHES
ADD_DEFINITIONS(-Wsign-compare)
ADD_DEFINITIONS(-std=c99)
ADD_DEFINITIONS(-pedantic)
ADD_DEFINITIONS(-Wshadow)
ADD_DEFINITIONS(-Wmissing-prototypes)
ADD_DEFINITIONS(-Wimplicit-fallthrough)
#ADD_DEFINITIONS(-Wfloat-equal)
#ADD_DEFINITIONS(-Wbad-function-cast)
#ADD_DEFINITIONS(-Wdocumentation)

# for strdup, setenv, use either
#ADD_DEFINITIONS(-D_POSIX_C_SOURCE=200809) # does not work with uClibc
ADD_DEFINITIONS(-D_GNU_SOURCE)
Expand Down
2 changes: 1 addition & 1 deletion include/baseband.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ void baseband_low_pass_filter(uint16_t const *x_buf, int16_t *y_buf, uint32_t le
@param x_buf input samples (I/Q samples in interleaved uint8)
@param[out] y_buf output from FM demodulator
@param num_samples number of samples to process
@param low_pass Low-pass filter frequency or ratio
@param[in,out] state State to store between chunk processing
@param fpdm Index of filter setting to use
*/
void baseband_demod_FM(uint8_t const *x_buf, int16_t *y_buf, unsigned long num_samples, uint32_t samp_rate, float low_pass, demodfm_state_t *state);

Expand Down
8 changes: 3 additions & 5 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,9 @@ add_library(r_433 STATIC
devices/x10_sec.c
)

if("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
set_source_files_properties(mongoose.c PROPERTIES COMPILE_FLAGS "-Wno-format -Wno-format-security")
endif()
if("${CMAKE_C_COMPILER_ID}" MATCHES "Clang")
set_source_files_properties(mongoose.c PROPERTIES COMPILE_FLAGS "-Wno-format-pedantic -Wno-format-security -Wno-large-by-value-copy")
if("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_C_COMPILER_ID}" MATCHES "Clang")
# untouched upstream code, disable all warnings
set_source_files_properties(mongoose.c PROPERTIES COMPILE_FLAGS "-w")
endif()

add_executable(rtl_433 rtl_433.c)
Expand Down
1 change: 1 addition & 0 deletions src/compat_alarm.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ int win_alarm(unsigned seconds)
/*
* Just so this compilation unit isn't empty.
*/
int win_alarm(unsigned seconds);
int win_alarm(unsigned seconds)
{
(void) seconds;
Expand Down
2 changes: 1 addition & 1 deletion src/data_tag.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ static data_t *append_filtered_json(data_t *data, char const *json, char const *
{
jsmn_parser parser = {0};
jsmn_init(&parser);
jsmntok_t tok[MAX_JSON_TOKENS] = {0};
jsmntok_t tok[MAX_JSON_TOKENS] = {{0}}; // make the compiler happy, should be {0}

int toks = jsmn_parse(&parser, json, strlen(json), tok, MAX_JSON_TOKENS);
if (toks < 1 || tok[0].type != JSMN_OBJECT) {
Expand Down
4 changes: 3 additions & 1 deletion src/devices/alecto.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ Format for Winddirection & Windgust:

#include "decoder.h"

/* return 1 if the checksum passes and 0 if it fails */
// NOTE: this is used in prologue.c, springfield.c, and thermopro_tx2.c
int alecto_checksum(uint8_t *b);
// return 1 if the checksum passes and 0 if it fails
int alecto_checksum(uint8_t *b)
{
int csum = 0;
Expand Down
31 changes: 16 additions & 15 deletions src/devices/burnhardbbq.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@ static int burnhardbbq_decode(r_device *decoder, bitbuffer_t *bitbuffer)
uint8_t *b;
data_t *data;

uint8_t id, channel, temperature_alarm, timer_alarm, timer_active;
float temperature, temperature_setpoint;
char timer_str[6];
char *meat, *taste;

bitbuffer_invert(bitbuffer);

// All three rows contain the same information. Return on first decoded row.
Expand All @@ -65,15 +60,20 @@ static int burnhardbbq_decode(r_device *decoder, bitbuffer_t *bitbuffer)
continue;
}

id = b[0];
channel = b[1] & 0x07;
temperature_alarm = (b[1] & 0x80) > 0;
timer_alarm = (b[1] & 0x40) > 0;
timer_active = (b[1] & 0x10) > 0;
temperature_setpoint = ((b[6] | (b[7] & 0x0f) << 8) - 500) * 0.1f;
temperature = ((b[8] | (b[7] & 0xf0) << 4) - 500) * 0.1f;
int id = (b[0]);
int channel = (b[1] & 0x07);
int temp_alarm = (b[1] & 0x80) > 7;
int timer_alarm = (b[1] & 0x40) > 6;
int timer_active = (b[1] & 0x10) > 4;
int setpoint_raw = ((b[7] & 0x0f) << 8) | b[6];
int temp_raw = ((b[7] & 0xf0) << 4) | b[8];
float setpoint_c = (setpoint_raw - 500) * 0.1f;
float temp_c = (temp_raw - 500) * 0.1f;

char timer_str[6];
sprintf(timer_str, "%02x:%02x", b[3], b[4] & 0x7f);

char *meat;
switch(b[5] >> 4) {
case 0: meat = "free"; break;
case 1: meat = "beef"; break;
Expand All @@ -86,6 +86,7 @@ static int burnhardbbq_decode(r_device *decoder, bitbuffer_t *bitbuffer)
default: meat = "";
}

char *taste;
switch(b[5] & 0x0f) {
case 0: taste = "rare"; break;
case 1: taste = "medium rare"; break;
Expand All @@ -100,9 +101,9 @@ static int burnhardbbq_decode(r_device *decoder, bitbuffer_t *bitbuffer)
"model", "", DATA_STRING, "BurnhardBBQ",
"id", "ID", DATA_INT, id,
"channel", "Channel", DATA_INT, channel,
"temperature_C", "Temperature", DATA_COND, temperature != -50.0f, DATA_FORMAT, "%.01f C", DATA_DOUBLE, temperature,
"setpoint_C", "Temperature setpoint", DATA_FORMAT, "%.0f C", DATA_DOUBLE, temperature_setpoint,
"temperature_alarm", "Temperature alarm", DATA_INT, temperature_alarm,
"temperature_C", "Temperature", DATA_COND, temp_raw != 0, DATA_FORMAT, "%.01f C", DATA_DOUBLE, temp_c,
"setpoint_C", "Temperature setpoint", DATA_FORMAT, "%.0f C", DATA_DOUBLE, setpoint_c,
"temperature_alarm", "Temperature alarm", DATA_INT, temp_alarm,
"timer", "Timer", DATA_STRING, timer_str,
"timer_active", "Timer active", DATA_INT, timer_active,
"timer_alarm", "Timer alarm", DATA_INT, timer_alarm,
Expand Down
6 changes: 3 additions & 3 deletions src/devices/directv.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ static const char *dtv_button_label[] = {
[0x100] = "unknown",
};

const char *get_dtv_button_label(uint8_t button_id)
static const char *get_dtv_button_label(uint8_t button_id)
{
const char *label = dtv_button_label[button_id];
if (!label) {
Expand All @@ -186,7 +186,7 @@ const char *get_dtv_button_label(uint8_t button_id)

/// Set a single bit in a bitrow at bit_idx position. Assume success, no bounds checking, so be careful!
/// Maybe this can graduate to bitbuffer.c someday?
void bitrow_set_bit(uint8_t *bitrow, unsigned bit_idx, unsigned bit_val)
static void bitrow_set_bit(uint8_t *bitrow, unsigned bit_idx, unsigned bit_val)
{
if (bit_val == 0) {
bitrow[bit_idx >> 3] &= ~(1 << (7 - (bit_idx & 7)));
Expand Down Expand Up @@ -222,7 +222,7 @@ void bitrow_set_bit(uint8_t *bitrow, unsigned bit_idx, unsigned bit_val)
/// sync_pos. If desired, call again with bit_len = sync_pos to find this data.
///
/// Maybe this can graduate to bitbuffer.c someday?
unsigned bitrow_dpwm_decode(uint8_t const *bitrow, unsigned bit_len, unsigned start,
static unsigned bitrow_dpwm_decode(uint8_t const *bitrow, unsigned bit_len, unsigned start,
uint8_t *bitrow_buf, unsigned *sync_pos, unsigned *sync_len)
{
unsigned bitrow_pos;
Expand Down
9 changes: 6 additions & 3 deletions src/devices/flex.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ static inline int bit(const uint8_t *bytes, unsigned bit)
}

/// extract all mask bits skipping unmasked bits of a number up to 32/64 bits
unsigned long compact_number(uint8_t *data, unsigned bit_offset, unsigned long mask)
static unsigned long compact_number(uint8_t *data, unsigned bit_offset, unsigned long mask)
{
// clz (fls) is not worth the trouble
int top_bit = 0;
Expand All @@ -38,7 +38,7 @@ unsigned long compact_number(uint8_t *data, unsigned bit_offset, unsigned long m
}

/// extract a number up to 32/64 bits from given offset with given bit length
unsigned long extract_number(uint8_t *data, unsigned bit_offset, unsigned bit_count)
static unsigned long extract_number(uint8_t *data, unsigned bit_offset, unsigned bit_count)
{
unsigned pos = bit_offset / 8; // the first byte we need
unsigned shl = bit_offset - pos * 8; // shift left we need to align
Expand Down Expand Up @@ -429,7 +429,7 @@ static unsigned parse_bits(const char *code, uint8_t *bitrow)
return len;
}

const char *parse_map(const char *arg, struct flex_get *getter)
static const char *parse_map(const char *arg, struct flex_get *getter)
{
const char *c = arg;
int i = 0;
Expand Down Expand Up @@ -511,6 +511,9 @@ static void parse_getter(const char *arg, struct flex_get *getter)
*/
}

// NOTE: this is declared in rtl_433.c also.
r_device *flex_create_device(char *spec);

r_device *flex_create_device(char *spec)
{
if (!spec || !*spec || *spec == '?' || !strncasecmp(spec, "help", strlen(spec))) {
Expand Down
2 changes: 1 addition & 1 deletion src/devices/ge_coloreffects.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ static inline int bit(const uint8_t *bytes, unsigned bit)
* 10 = 0
* 1100 = 1
*/
unsigned ge_decode(bitbuffer_t *inbuf, unsigned row, unsigned start, bitbuffer_t *outbuf)
static unsigned ge_decode(bitbuffer_t *inbuf, unsigned row, unsigned start, bitbuffer_t *outbuf)
{
uint8_t *bits = inbuf->bb[row];
unsigned int len = inbuf->bits_per_row[row];
Expand Down
19 changes: 10 additions & 9 deletions src/devices/m_bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ static int m_bus_crc_valid(r_device *decoder, const uint8_t *bytes, unsigned crc


// Decode two bytes into three letters of five bits
static void m_bus_manuf_decode(uint16_t m_field, char* three_letter_code)
static void m_bus_manuf_decode(uint16_t m_field, char *three_letter_code)
{
three_letter_code[0] = (m_field >> 10 & 0x1F) + 0x40;
three_letter_code[1] = (m_field >> 5 & 0x1F) + 0x40;
Expand All @@ -96,7 +96,7 @@ static void m_bus_manuf_decode(uint16_t m_field, char* three_letter_code)


// Decode device type string
const char* m_bus_device_type_str(uint8_t devType)
static char const *m_bus_device_type_str(uint8_t devType)
{
char *str = "";
switch(devType) {
Expand Down Expand Up @@ -179,14 +179,14 @@ typedef struct {
static float humidity_factor[2] = { 0.1, 1 };


static char* oms_hum[4][4] = {
static char *oms_hum[4][4] = {
{"humidity","average_humidity_1h","average_humidity_24h","error_04", },
{"maximum_humidity_1h","maximum_humidity_24h","error_13","error_14",},
{"minimum_humidity_1h","minimum_humidity_24h","error_23","error_24",},
{"error_31","error_32","error_33","error_34",}
};

static char* oms_hum_el[4][4] = {
static char *oms_hum_el[4][4] = {
{"Humidity","Average Humidity 1h","Average Humidity 24h","Error [0][4]", },
{"Maximum Humidity 1h","Maximum Humidity 24h","Error [1][3]","Error [1][4]",},
{"Minimum Humidity 1h","Minimum Humidity 24h","Error [2][3]","Error [2][4]",},
Expand Down Expand Up @@ -282,7 +282,7 @@ static char *unit_names[][3] = {
static double pow10_table[8] = { 0.001, 0.01, 0.1, 1, 10, 100, 1000, 10000 };


static data_t *append_str(data_t *data, enum UnitType unit_type, uint8_t value_type, uint8_t sn, const char* extra, const char* value)
static data_t *append_str(data_t *data, enum UnitType unit_type, uint8_t value_type, uint8_t sn, char const *extra, char const *value)
{
char key[100] = {0};
char pretty[100] = {0};
Expand All @@ -301,9 +301,9 @@ static data_t *append_str(data_t *data, enum UnitType unit_type, uint8_t value_t

}

static data_t *append_val(data_t *data, enum UnitType unit_type, uint8_t value_type, uint8_t sn, const char* extra, int64_t val, int exp)
static data_t *append_val(data_t *data, enum UnitType unit_type, uint8_t value_type, uint8_t sn, char const *extra, int64_t val, int exp)
{
const char *prefix = "";
char const *prefix = "";
char buffer_val[256] = {0};

if (exp < -6) {
Expand Down Expand Up @@ -337,7 +337,7 @@ static data_t *append_val(data_t *data, enum UnitType unit_type, uint8_t value_t
return append_str(data, unit_type, value_type, sn, extra, buffer_val);
}

size_t m_bus_tm_decode(const uint8_t *data, size_t data_size, char *output, size_t output_size)
static size_t m_bus_tm_decode(const uint8_t *data, size_t data_size, char *output, size_t output_size)
{
size_t out_len = 0;

Expand Down Expand Up @@ -657,6 +657,7 @@ static int m_bus_decode_records(data_t *data, const uint8_t *b, uint8_t dif_codi
default:
break;
}
break;
default:
break;
}
Expand Down Expand Up @@ -863,7 +864,7 @@ static int m_bus_decode_format_b(r_device *decoder, const m_bus_data_t *in, m_bu
return 1;
}

static int m_bus_output_data(r_device *decoder, bitbuffer_t *bitbuffer, const m_bus_data_t *out, const m_bus_block1_t *block1, const char *mode)
static int m_bus_output_data(r_device *decoder, bitbuffer_t *bitbuffer, const m_bus_data_t *out, const m_bus_block1_t *block1, char const *mode)
{
(void)bitbuffer; // note: to match the common decoder function signature

Expand Down
2 changes: 2 additions & 0 deletions src/devices/rubicson.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ The sensor can be bought at Kjell&Co
#include "decoder.h"

// NOTE: this is used in nexus.c and solight_te44.c
int rubicson_crc_check(uint8_t *b);

int rubicson_crc_check(uint8_t *b)
{
uint8_t tmp[5];
Expand Down
2 changes: 1 addition & 1 deletion src/devices/secplus_v2.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Once the above has been run twice the two are merged
*/

int _decode_v2_half(bitbuffer_t *bits, uint8_t roll_array[], bitbuffer_t *fixed_p, int verbose)
static int _decode_v2_half(bitbuffer_t *bits, uint8_t roll_array[], bitbuffer_t *fixed_p, int verbose)
{
uint8_t invert = 0;
uint8_t order = 0;
Expand Down
30 changes: 15 additions & 15 deletions src/fileformat.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,19 @@ void check_write_file_info(file_info_t *info)
char const *file_info_string(file_info_t *info)
{
switch (info->format) {
case CU8_IQ: return "CU8 IQ (2ch uint8)"; break;
case S16_AM: return "S16 AM (1ch int16)"; break;
case S16_FM: return "S16 FM (1ch int16)"; break;
case CF32_IQ: return "CF32 IQ (2ch float32)"; break;
case CS16_IQ: return "CS16 IQ (2ch int16)"; break;
case F32_AM: return "F32 AM (1ch float32)"; break;
case F32_FM: return "F32 FM (1ch float32)"; break;
case F32_I: return "F32 I (1ch float32)"; break;
case F32_Q: return "F32 Q (1ch float32)"; break;
case VCD_LOGIC: return "VCD logic (text)"; break;
case U8_LOGIC: return "U8 logic (1ch uint8)"; break;
case PULSE_OOK: return "OOK pulse data (text)"; break;
default: return "Unknown"; break;
case CU8_IQ: return "CU8 IQ (2ch uint8)";
case S16_AM: return "S16 AM (1ch int16)";
case S16_FM: return "S16 FM (1ch int16)";
case CF32_IQ: return "CF32 IQ (2ch float32)";
case CS16_IQ: return "CS16 IQ (2ch int16)";
case F32_AM: return "F32 AM (1ch float32)";
case F32_FM: return "F32 FM (1ch float32)";
case F32_I: return "F32 I (1ch float32)";
case F32_Q: return "F32 Q (1ch float32)";
case VCD_LOGIC: return "VCD logic (text)";
case U8_LOGIC: return "U8 logic (1ch uint8)";
case PULSE_OOK: return "OOK pulse data (text)";
default: return "Unknown";
}
}

Expand Down Expand Up @@ -270,7 +270,7 @@ int parse_file_info(char const *filename, file_info_t *info)

// Unit testing
#ifdef _TEST
void assert_file_type(int check, char const *spec)
static void assert_file_type(int check, char const *spec)
{
file_info_t info = {0};
int ret = parse_file_info(spec, &info);
Expand All @@ -281,7 +281,7 @@ void assert_file_type(int check, char const *spec)
}
}

void assert_str_equal(char const *a, char const *b)
static void assert_str_equal(char const *a, char const *b)
{
if (a != b && (!a || !b || strcmp(a, b))) {
fprintf(stderr, "\nTEST failed: \"%s\" == \"%s\"\n", a, b);
Expand Down
Loading

0 comments on commit 6c8af75

Please sign in to comment.