Make most of functions const correct (#714)
* Make most of the functions const correct
Used clang-tidy and sonarlint to help find places where const could
pretty easily applied. Also lot of hand work.
This commit does not yet touch handlers and typedefs of those.
* Fix Arduino uno handler_who_is() has extra parenthesis
For some reason there is extra parenthesis. Remove it this is more
likely buildable.
* Bugfix/bacapp: Fix uninitilized array_index
We have changed bacapp_snprintf_value() to be const correct. After that
we got
```
/home/runner/work/bacnet-stack/bacnet-stack/src/bacnet/bacapp.c:3183:27: warning: 4th function call argument is an uninitialized value [core.CallAndMessage]
ret_val = bacapp_snprintf_weeklyschedule(
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.
```
So analyzer could now spot that we do not actually initilize array_index
at all. Fix this by setting array_index to zero. Note that I actually do
not know if zeroing is right thing to do here. I choose zero as if this
has worked before it is most likely that it will work with zero value.
* cmake: Add and ignore Wwrite-strings compiler option
Wwrite-strings helps find places where const correctness is broken.
Example it will warn about these
```C
void func1(char* str);
func("test") /* "test" is const so we should not pass it to func1().
char* func2()
{
return "test"; /* func2() should return const char*.
}
```
We still need to ignore it as not all are fixed but let's add it already
so we remember that it should be opened at some point.
---------
Co-authored-by: Kari Argillander <kari.argillander@fidelix.com>
This commit is contained in:
@@ -199,7 +199,10 @@ bool dl_ip_init(ROUTER_PORT *port, IP_DATA *ip_data)
|
||||
}
|
||||
|
||||
int dl_ip_send(
|
||||
IP_DATA *data, BACNET_ADDRESS *dest, uint8_t *pdu, unsigned pdu_len)
|
||||
IP_DATA *data,
|
||||
const BACNET_ADDRESS *dest,
|
||||
const uint8_t *pdu,
|
||||
unsigned pdu_len)
|
||||
{
|
||||
struct sockaddr_in bip_dest = { 0 };
|
||||
int buff_len = 0;
|
||||
|
||||
@@ -45,8 +45,8 @@ bool dl_ip_init(
|
||||
|
||||
int dl_ip_send(
|
||||
IP_DATA * data,
|
||||
BACNET_ADDRESS * dest,
|
||||
uint8_t * pdu,
|
||||
const BACNET_ADDRESS * dest,
|
||||
const uint8_t * pdu,
|
||||
unsigned pdu_len);
|
||||
|
||||
int dl_ip_recv(
|
||||
|
||||
+8
-8
@@ -43,7 +43,7 @@ int port_count;
|
||||
|
||||
void print_help(void);
|
||||
|
||||
bool read_config(char *filepath);
|
||||
bool read_config(const char *filepath);
|
||||
|
||||
bool parse_cmd(int argc, char *argv[]);
|
||||
|
||||
@@ -53,7 +53,7 @@ bool init_router(void);
|
||||
|
||||
void cleanup(void);
|
||||
|
||||
void print_msg(BACMSG *msg);
|
||||
void print_msg(const BACMSG *msg);
|
||||
|
||||
uint16_t process_msg(BACMSG *msg, MSG_DATA *data, uint8_t **buff);
|
||||
|
||||
@@ -61,7 +61,7 @@ uint16_t get_next_free_dnet(void);
|
||||
|
||||
int kbhit(void);
|
||||
|
||||
inline bool is_network_msg(BACMSG *msg);
|
||||
inline bool is_network_msg(const BACMSG *msg);
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
@@ -201,7 +201,7 @@ void print_help(void)
|
||||
"-s, --stopbits <1|2>\n\tspecify MSTP port stopbits\n");
|
||||
}
|
||||
|
||||
bool read_config(char *filepath)
|
||||
bool read_config(const char *filepath)
|
||||
{
|
||||
config_t cfg;
|
||||
config_setting_t *setting;
|
||||
@@ -725,11 +725,11 @@ void cleanup(void)
|
||||
pthread_mutex_destroy(&msg_lock);
|
||||
}
|
||||
|
||||
void print_msg(BACMSG *msg)
|
||||
void print_msg(const BACMSG *msg)
|
||||
{
|
||||
if (msg->type == DATA) {
|
||||
int i;
|
||||
MSG_DATA *data = (MSG_DATA *)msg->data;
|
||||
const MSG_DATA *data = (const MSG_DATA *)msg->data;
|
||||
|
||||
if (data->pdu_len) {
|
||||
PRINT(DEBUG, "Message PDU: ");
|
||||
@@ -821,10 +821,10 @@ int kbhit(void)
|
||||
return bytesWaiting;
|
||||
}
|
||||
|
||||
bool is_network_msg(BACMSG *msg)
|
||||
bool is_network_msg(const BACMSG *msg)
|
||||
{
|
||||
uint8_t control_byte; /* NPDU control byte */
|
||||
MSG_DATA *data = (MSG_DATA *)msg->data;
|
||||
const MSG_DATA *data = (const MSG_DATA *)msg->data;
|
||||
|
||||
control_byte = data->pdu[1];
|
||||
|
||||
|
||||
@@ -14,7 +14,8 @@
|
||||
#include "network_layer.h"
|
||||
#include "bacnet/bacint.h"
|
||||
|
||||
uint16_t process_network_message(BACMSG *msg, MSG_DATA *data, uint8_t **buff)
|
||||
uint16_t process_network_message(
|
||||
const BACMSG *msg, MSG_DATA *data, uint8_t **buff)
|
||||
{
|
||||
BACNET_NPDU_DATA npdu_data;
|
||||
ROUTER_PORT *srcport;
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
#include "portthread.h"
|
||||
|
||||
uint16_t process_network_message(
|
||||
BACMSG * msg,
|
||||
const BACMSG * msg,
|
||||
MSG_DATA * data,
|
||||
uint8_t ** buff);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user