Minor fixes for clangd warnings
This commit is contained in:
parent
a25ee5781a
commit
363e7f7480
16
.clang-tidy
16
.clang-tidy
@ -1,16 +1,18 @@
|
||||
---
|
||||
Checks: >
|
||||
modernize-*,
|
||||
performance-*,
|
||||
readability-*,
|
||||
bugprone-*,
|
||||
*,
|
||||
-altera-*,
|
||||
-bugprone-easily-swappable-parameters,
|
||||
-cppcoreguidelines-avoid-magic-numbers,
|
||||
-cppcoreguidelines-avoid-non-const-global-variables,
|
||||
-google-readability-braces-around-statements,
|
||||
-hicpp-braces-around-statements,
|
||||
-hicpp-signed-bitwise,
|
||||
-llvmlibc-restrict-system-libc-headers,
|
||||
-readability-braces-around-statements,
|
||||
-readability-magic-numbers,
|
||||
-readability-function-cognitive-complexity,
|
||||
-readability-identifier-length
|
||||
-readability-identifier-length,
|
||||
...
|
||||
|
||||
WarningsAsErrors: '*'
|
||||
HeaderFilterRegex: ''
|
||||
FormatStyle: none
|
||||
|
||||
@ -4,7 +4,7 @@ project(nanomodbus C)
|
||||
set(CMAKE_C_STANDARD 99)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -pedantic -Wswitch-enum -Wcast-qual -Woverflow")
|
||||
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0 -g")
|
||||
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3")
|
||||
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3 -g0")
|
||||
|
||||
include_directories(tests examples/linux .)
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2022 Valerio De Benedetto (@debevv)
|
||||
Copyright (c) 2024 Valerio De Benedetto (@debevv)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
@ -27,6 +27,7 @@
|
||||
#include "nanomodbus.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef NMBS_DEBUG
|
||||
@ -423,7 +424,7 @@ static nmbs_error recv_res_header(nmbs_t* nmbs) {
|
||||
uint8_t req_unit_id = nmbs->msg.unit_id;
|
||||
uint8_t req_fc = nmbs->msg.fc;
|
||||
|
||||
bool first_byte_received;
|
||||
bool first_byte_received = false;
|
||||
nmbs_error err = recv_msg_header(nmbs, &first_byte_received);
|
||||
if (err != NMBS_ERROR_NONE)
|
||||
return err;
|
||||
@ -1710,7 +1711,7 @@ static nmbs_error handle_read_device_identification(nmbs_t* nmbs) {
|
||||
|
||||
int16_t str_len = (int16_t) strlen(str);
|
||||
|
||||
res_size_left = res_size_left - 2 - str_len;
|
||||
res_size_left = (int16_t) (res_size_left - 2 - str_len);
|
||||
if (res_size_left < 0) {
|
||||
res_more_follows = 0xFF;
|
||||
res_next_object_id = id;
|
||||
@ -1747,7 +1748,7 @@ static nmbs_error handle_read_device_identification(nmbs_t* nmbs) {
|
||||
static nmbs_error handle_req_fc(nmbs_t* nmbs) {
|
||||
NMBS_DEBUG_PRINT("fc %d\t", nmbs->msg.fc);
|
||||
|
||||
nmbs_error err;
|
||||
nmbs_error err = NMBS_ERROR_NONE;
|
||||
switch (nmbs->msg.fc) {
|
||||
#ifndef NMBS_SERVER_WRITE_MULTIPLE_COILS_DISABLED
|
||||
case 1:
|
||||
|
||||
11
nanomodbus.h
11
nanomodbus.h
@ -3,7 +3,7 @@
|
||||
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2022 Valerio De Benedetto (@debevv)
|
||||
Copyright (c) 2024 Valerio De Benedetto (@debevv)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
@ -42,7 +42,6 @@
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -440,12 +439,12 @@ nmbs_error nmbs_read_write_registers(nmbs_t* nmbs, uint16_t read_address, uint16
|
||||
* @param vendor_name char array where the read VendorName value will be stored
|
||||
* @param product_code char array where the read ProductCode value will be stored
|
||||
* @param major_minor_revision char array where the read MajorMinorRevision value will be stored
|
||||
* @param buffer_length length of every char array
|
||||
* @param buffers_length length of every char array
|
||||
*
|
||||
* @return NMBS_ERROR_NONE if successful, other errors otherwise.
|
||||
*/
|
||||
nmbs_error nmbs_read_device_identification_basic(nmbs_t* nmbs, char* vendor_name, char* product_code,
|
||||
char* major_minor_revision, uint8_t buffer_length);
|
||||
char* major_minor_revision, uint8_t buffers_length);
|
||||
|
||||
/** Send a FC 43 / 14 (0x2B / 0x0E) Read Device Identification to read all Regular Object Id values (Read Device ID code 2)
|
||||
* @param nmbs pointer to the nmbs_t instance
|
||||
@ -453,12 +452,12 @@ nmbs_error nmbs_read_device_identification_basic(nmbs_t* nmbs, char* vendor_name
|
||||
* @param product_name char array where the read ProductName value will be stored
|
||||
* @param model_name char array where the read ModelName value will be stored
|
||||
* @param user_application_name char array where the read UserApplicationName value will be stored
|
||||
* @param buffer_length length of every char array
|
||||
* @param buffers_length length of every char array
|
||||
*
|
||||
* @return NMBS_ERROR_NONE if successful, other errors otherwise.
|
||||
*/
|
||||
nmbs_error nmbs_read_device_identification_regular(nmbs_t* nmbs, char* vendor_url, char* product_name, char* model_name,
|
||||
char* user_application_name, uint8_t buffer_length);
|
||||
char* user_application_name, uint8_t buffers_length);
|
||||
|
||||
/** Send a FC 43 / 14 (0x2B / 0x0E) Read Device Identification to read all Extended Object Id values (Read Device ID code 3)
|
||||
* @param nmbs pointer to the nmbs_t instance
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
#undef NDEBUG
|
||||
#include <assert.h>
|
||||
#include <pthread.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/select.h>
|
||||
@ -40,14 +41,14 @@ nmbs_t CLIENT, SERVER;
|
||||
printf("Should %s\n", (s))
|
||||
|
||||
|
||||
uint64_t now_ms() {
|
||||
uint64_t now_ms(void) {
|
||||
struct timespec ts = {0, 0};
|
||||
clock_gettime(CLOCK_MONOTONIC_RAW, &ts);
|
||||
return (uint64_t) (ts.tv_sec) * 1000 + (uint64_t) (ts.tv_nsec) / 1000000;
|
||||
}
|
||||
|
||||
|
||||
void reset_sockets() {
|
||||
void reset_sockets(void) {
|
||||
if (sockets[0] != -1)
|
||||
close(sockets[0]);
|
||||
|
||||
@ -70,20 +71,20 @@ int32_t read_fd(int fd, uint8_t* buf, uint16_t count, int32_t timeout_ms) {
|
||||
if (timeout_ms >= 0) {
|
||||
tv_p = &tv;
|
||||
tv.tv_sec = timeout_ms / 1000;
|
||||
tv.tv_usec = (timeout_ms % 1000) * 1000;
|
||||
tv.tv_usec = ((__suseconds_t) timeout_ms % 1000) * 1000;
|
||||
}
|
||||
|
||||
int ret = select(fd + 1, &rfds, NULL, NULL, tv_p);
|
||||
if (ret == 0) {
|
||||
return total;
|
||||
}
|
||||
else if (ret == 1) {
|
||||
|
||||
if (ret == 1) {
|
||||
ssize_t r = read(fd, buf + total, 1);
|
||||
if (r <= 0)
|
||||
return -1;
|
||||
else {
|
||||
total += r;
|
||||
}
|
||||
|
||||
total += r;
|
||||
}
|
||||
else
|
||||
return -1;
|
||||
@ -105,20 +106,20 @@ int32_t write_fd(int fd, const uint8_t* buf, uint16_t count, int32_t timeout_ms)
|
||||
if (timeout_ms >= 0) {
|
||||
tv_p = &tv;
|
||||
tv.tv_sec = timeout_ms / 1000;
|
||||
tv.tv_usec = (timeout_ms % 1000) * 1000;
|
||||
tv.tv_usec = ((__suseconds_t) timeout_ms % 1000) * 1000;
|
||||
}
|
||||
|
||||
int ret = select(fd + 1, NULL, &wfds, NULL, tv_p);
|
||||
if (ret == 0) {
|
||||
return 0;
|
||||
}
|
||||
else if (ret == 1) {
|
||||
|
||||
if (ret == 1) {
|
||||
ssize_t w = write(fd, buf + total, count);
|
||||
if (w <= 0)
|
||||
return -1;
|
||||
else {
|
||||
total += w;
|
||||
}
|
||||
|
||||
total += w;
|
||||
}
|
||||
else
|
||||
return -1;
|
||||
@ -170,7 +171,7 @@ nmbs_platform_conf* platform_conf_socket_client(nmbs_transport transport) {
|
||||
}
|
||||
|
||||
|
||||
bool is_server_listen_thread_stopped() {
|
||||
bool is_server_listen_thread_stopped(void) {
|
||||
bool stopped = false;
|
||||
expect(pthread_mutex_lock(&server_stopped_m) == 0);
|
||||
stopped = server_stopped;
|
||||
@ -179,7 +180,8 @@ bool is_server_listen_thread_stopped() {
|
||||
}
|
||||
|
||||
|
||||
void* server_listen_thread() {
|
||||
void* server_listen_thread(void* arg) {
|
||||
UNUSED_PARAM(arg);
|
||||
while (true) {
|
||||
if (is_server_listen_thread_stopped())
|
||||
break;
|
||||
@ -190,8 +192,7 @@ void* server_listen_thread() {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
void stop_client_and_server() {
|
||||
void stop_client_and_server(void) {
|
||||
if (!is_server_listen_thread_stopped()) {
|
||||
expect(pthread_mutex_lock(&server_stopped_m) == 0);
|
||||
server_stopped = true;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user