Fix more clang-tidy warnings

This commit is contained in:
Tobias Reisinger 2020-11-14 00:34:20 +01:00
parent 5747a65664
commit c7cafa94c4
21 changed files with 178 additions and 208 deletions

View file

@ -1,2 +1,2 @@
---
Checks: 'clang-diagnostics-*,clang-analyzer-*,linuxkernel-*,modernize-*,readability-*'
Checks: 'clang-diagnostics-*,clang-analyzer-*,linuxkernel-*,modernize-*,readability-*,-readability-magic-numbers,portability-*'

View file

@ -21,10 +21,10 @@ void
database_transaction_begin(database_transaction_lock *lock);
void
database_transaction_commit(database_transaction_lock *lock);
database_transaction_commit(const database_transaction_lock *lock);
void
database_transaction_rollback(database_transaction_lock *lock);
database_transaction_rollback(const database_transaction_lock *lock);
int

View file

@ -25,16 +25,16 @@ typedef struct
} controller_t;
void
controller_free(controller_t* contoller);
controller_free(controller_t *controller);
int
controller_save(controller_t* contoller);
controller_save(controller_t *controller);
int
controller_remove(controller_t* contoller);
controller_remove(controller_t *controller);
cJSON*
controller_to_json(controller_t* contoller);
controller_to_json(controller_t *controller);
controller_t*
controller_get_by_id(int id);

View file

@ -30,9 +30,6 @@ macro_free_list(macro_t **macro);
cJSON*
macro_to_json(macro_t *macro);
void
macro_free_list(macro_t **macros_list);
macro_t*
macro_get_by_id(int id);

View file

@ -35,9 +35,6 @@ schedule_free_list(schedule_t **schedule);
cJSON*
schedule_to_json(schedule_t *schedule);
void
schedule_free_list(schedule_t **schedules_list);
uint16_t*
schedule_periods_to_blob(schedule_t *schedule);

View file

@ -42,13 +42,11 @@ cache_get_value(char *key)
{
break;
}
else
{
LOGGER_WARNING("failed selecting %s from cache: %s\n", key, sqlite3_errstr(s));
break;
}
}
}
sqlite3_finalize(stmt);

View file

@ -47,5 +47,4 @@ cli_parse(int argc, const char **argv, config_t *config)
printf("%s\n", EMGAUWA_CORE_VERSION);
exit(0);
}
return;
}

View file

@ -90,8 +90,6 @@ database_migrate()
default:
break;
}
return;
}
void
@ -106,7 +104,7 @@ database_transaction_begin(database_transaction_lock *lock)
}
void
database_transaction_commit(database_transaction_lock *lock)
database_transaction_commit(const database_transaction_lock *lock)
{
if(transaction_lock == lock)
{
@ -117,7 +115,7 @@ database_transaction_commit(database_transaction_lock *lock)
}
void
database_transaction_rollback(database_transaction_lock *lock)
database_transaction_rollback(const database_transaction_lock *lock)
{
if(transaction_lock == lock)
{
@ -147,14 +145,12 @@ database_helper_get_id(sqlite3_stmt *stmt)
{
break;
}
else
{
LOGGER_ERR("error selecting id from database: %s\n", sqlite3_errstr(s));
sqlite3_finalize(stmt);
return 0;
}
}
}
sqlite3_finalize(stmt);
@ -191,8 +187,7 @@ database_helper_get_ids(sqlite3_stmt *stmt)
{
break;
}
else
{
if(result)
{
free(result);
@ -202,7 +197,6 @@ database_helper_get_ids(sqlite3_stmt *stmt)
return NULL;
}
}
}
sqlite3_finalize(stmt);
result[row] = 0;
@ -238,8 +232,7 @@ database_helper_get_string(sqlite3_stmt *stmt)
{
break;
}
else
{
if(result)
{
free(result);
@ -249,7 +242,6 @@ database_helper_get_string(sqlite3_stmt *stmt)
return NULL;
}
}
}
sqlite3_finalize(stmt);
@ -284,13 +276,11 @@ database_helper_get_strings(sqlite3_stmt *stmt)
{
break;
}
else
{
LOGGER_ERR("error selecting strings from database: %s\n", sqlite3_errstr(s));
break;
}
}
}
sqlite3_finalize(stmt);
result[row] = NULL;
return result;

View file

@ -168,5 +168,4 @@ api_v1_controllers_STR_DELETE(struct mg_connection *nc, struct http_message *hm,
M_RESPONSE_MSG(LOGGER_DEBUG, response, 200, "deleted controller");
}
controller_free(controller);
return;
}

View file

@ -21,7 +21,8 @@ typedef enum
static int
bind_tcp_server(const char *addr, const char *port, int max_client_backlog)
{
struct addrinfo hints, *res;
struct addrinfo hints;
struct addrinfo *res;
int fd;
int status;
@ -132,7 +133,8 @@ api_v1_controllers_discover_PUT(struct mg_connection *nc, struct http_message *h
struct sockaddr_storage their_addr;
socklen_t addr_size;
int client_fd, s_ret;
int s_ret;
int client_fd;
fd_set accept_fds;
struct timeval timeout;
@ -155,8 +157,7 @@ api_v1_controllers_discover_PUT(struct mg_connection *nc, struct http_message *h
{
break;
}
else
{
if((client_fd = accept(discover_server_socket, (struct sockaddr *) &their_addr, &addr_size)) < 0)
{
LOGGER_ERR("error accepting client %s\n", strerror(errno));
@ -292,7 +293,6 @@ api_v1_controllers_discover_PUT(struct mg_connection *nc, struct http_message *h
send(client_fd, discover_answer_buf, sizeof(uint8_t), 0);
close(client_fd);
}
}
for(int i = 0; known_controllers[i] != NULL; i++)
{
LOGGER_DEBUG("lost controller %s at %s\n", known_controllers[i]->name, known_controllers[i]->ip);

View file

@ -277,5 +277,4 @@ api_v1_macros_STR_DELETE(struct mg_connection *nc, struct http_message *hm, endp
M_RESPONSE_MSG(LOGGER_DEBUG, response, 200, "deleted macro");
}
macro_free(macro);
return;
}

View file

@ -204,5 +204,4 @@ api_v1_schedules_STR_DELETE(struct mg_connection *nc, struct http_message *hm, e
M_RESPONSE_MSG(LOGGER_DEBUG, response, 200, "the target schedule got deleted");
}
schedule_free(schedule);
return;
}

View file

@ -95,5 +95,4 @@ api_v1_tags_POST(struct mg_connection *nc, struct http_message *hm, endpoint_arg
}
cJSON_Delete(json);
return;
}

View file

@ -118,12 +118,10 @@ handle_http_request(struct mg_connection *nc, struct http_message *hm)
LOGGER_DEBUG("serving %.*s\n", hm->uri.len, hm->uri.p);
return;
}
else
{
LOGGER_DEBUG("serving 'not found'\n");
endpoint = router_get_not_found_endpoint();
}
}
if(endpoint->method == HTTP_METHOD_OPTIONS)
{

View file

@ -9,7 +9,7 @@
#include <models/relay.h>
static void
handle_mqtt_publish_controller(char **topic_save, int controller_id, char *payload)
handle_mqtt_publish_controller(char **topic_save, int controller_id, const char *payload)
{
(void)controller_id;
(void)payload;

View file

@ -13,8 +13,11 @@ helper_connect_tcp_server(char* host, uint16_t port)
char port_str[6];
sprintf(port_str, "%d", port);
int s, status;
struct addrinfo hints, *res;
int s;
int status;
struct addrinfo *res;
struct addrinfo hints;
memset(&hints, 0, sizeof hints);
hints.ai_family = AF_INET; //set IP Protocol flag (IPv4 or IPv6 - we don't care)
hints.ai_socktype = SOCK_STREAM; //set socket flag

View file

@ -105,13 +105,11 @@ controller_db_select(sqlite3_stmt *stmt)
{
break;
}
else
{
LOGGER_ERR("error selecting controllers from database: %s\n", sqlite3_errstr(s));
break;
}
}
}
sqlite3_finalize(stmt);
all_controllers[row] = NULL;
return all_controllers;

View file

@ -82,13 +82,11 @@ macro_db_select(sqlite3_stmt *stmt)
{
break;
}
else
{
LOGGER_ERR("error selecting macros from database: %s\n", sqlite3_errstr(s));
break;
}
}
}
sqlite3_finalize(stmt);
all_macros[row] = NULL;
return all_macros;

View file

@ -61,13 +61,11 @@ macro_action_db_select(sqlite3_stmt *stmt)
{
break;
}
else
{
LOGGER_ERR("error selecting macro_actions from database: %s\n", sqlite3_errstr(s));
break;
}
}
}
sqlite3_finalize(stmt);
all_macro_actions[row] = NULL;
return all_macro_actions;

View file

@ -27,9 +27,8 @@ period_helper_parse_hhmm(const char *hhmm_str, uint16_t *hhmm)
}
}
uint16_t tmp_h, tmp_m;
tmp_h = (uint16_t)strtol(&hhmm_str[0], NULL, 10);
tmp_m = (uint16_t)strtol(&hhmm_str[3], NULL, 10);
uint16_t tmp_h = (uint16_t)strtol(&hhmm_str[0], NULL, 10);
uint16_t tmp_m = (uint16_t)strtol(&hhmm_str[3], NULL, 10);
if(tmp_h > 24 || tmp_m >= 60)
{

View file

@ -314,7 +314,6 @@ router_find_endpoint(const char *uri_str, size_t uri_len, struct mg_str *method_
continue;
}
endpoints[i].possible_route = 0;
continue;
}
uri_token = strtok_r(NULL, delimiter, &uri_token_save);
++route_part;