Skip to content

Commit

Permalink
Make improvements suggested by clang-tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
mikee47 committed Apr 21, 2024
1 parent ee80185 commit 4b9fc84
Show file tree
Hide file tree
Showing 72 changed files with 359 additions and 269 deletions.
2 changes: 0 additions & 2 deletions Sming/Arch/Host/Components/driver/hw_timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ class CTimerThread : public CThread
private:
typedef std::ratio<HW_TIMER_BASE_CLK, 1000000> base_ticks_per_us;
uint32_t divisor = 1;
uint32_t frequency = HW_TIMER_BASE_CLK;
uint64_t start_time = 0;
uint64_t interval = 0; // In microseconds
CSemaphore sem; // Signals state change
Expand All @@ -130,7 +129,6 @@ class CTimerThread : public CThread
State state = stopped;

hw_timer_source_type_t source_type = TIMER_FRC1_SOURCE;
unsigned irq_level = 1;
struct {
hw_timer_callback_t func = nullptr;
void* arg = nullptr;
Expand Down
5 changes: 0 additions & 5 deletions Sming/Arch/Host/Components/driver/uart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,6 @@ void notify(smg_uart_t* uart, smg_uart_notify_code_t code)
}
}

__forceinline bool smg_uart_isr_enabled(uint8_t nr)
{
return bitRead(isrMask, nr);
}

} // namespace

smg_uart_t* smg_uart_get_uart(uint8_t uart_nr)
Expand Down
7 changes: 2 additions & 5 deletions Sming/Arch/Host/Components/esp_hal/clk.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,13 @@ static uint32_t base_ccount;
*/
static uint32_t get_ccount(uint64_t nanos)
{
uint32_t ccount;
if(base_nanos == 0) {
base_nanos = nanos;
base_ccount = nanos / cpu_frequency;
ccount = base_ccount;
} else {
ccount = base_ccount + cpu_frequency * ((nanos - base_nanos) / 1000);
return base_ccount;
}

return ccount;
return base_ccount + cpu_frequency * ((nanos - base_nanos) / 1000);
}

bool system_update_cpu_freq(uint8_t freq)
Expand Down
4 changes: 2 additions & 2 deletions Sming/Arch/Host/Components/esp_hal/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ static uint64_t initTime()
timeref.startTicks = os_get_nanoseconds();
#endif

timeval tv;
timeval tv{};
gettimeofday(&tv, nullptr);
return (1000000ULL * tv.tv_sec) + tv.tv_usec;
}
Expand All @@ -41,7 +41,7 @@ uint64_t os_get_nanoseconds()
QueryPerformanceCounter(&count);
return timeref.countsPerNanosecond * uint64_t(count.QuadPart - timeref.startCount.QuadPart);
#else
timespec ts;
timespec ts{};
clock_gettime(CLOCK_MONOTONIC, &ts);
return (1000000000ULL * ts.tv_sec) + ts.tv_nsec - timeref.startTicks;
#endif
Expand Down
9 changes: 3 additions & 6 deletions Sming/Arch/Host/Components/esp_hal/tasks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,8 @@ class TaskQueue
{
public:
TaskQueue(os_task_t callback, os_event_t* events, uint8_t length)
: callback(callback), events(events), length(length)
{
this->callback = callback;
this->events = events;
this->length = length;
read = count = 0;
}

bool post(os_signal_t sig, os_param_t par)
Expand Down Expand Up @@ -45,8 +42,8 @@ class TaskQueue
static CMutex mutex;
os_task_t callback;
os_event_t* events;
uint8_t read;
uint8_t count;
uint8_t read{0};
uint8_t count{0};
uint8_t length;
};

Expand Down
10 changes: 4 additions & 6 deletions Sming/Arch/Host/Components/hostlib/hostlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,12 @@ size_t getHostAppDir(char* path, size_t bufSize)
return 0;
}

size_t len;
char sep;
#ifdef __WIN32
len = GetModuleFileName(NULL, path, bufSize);
sep = '\\';
size_t len = GetModuleFileName(NULL, path, bufSize);
char sep = '\\';
#else
len = readlink("/proc/self/exe", path, bufSize - 1);
sep = '/';
size_t len = readlink("/proc/self/exe", path, bufSize - 1);
char sep = '/';
#endif
path[len] = '\0';
char* p = strrchr(path, sep);
Expand Down
2 changes: 1 addition & 1 deletion Sming/Arch/Host/Components/hostlib/hostmsg.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void host_printf(const char* fmt, ...)

void host_printfp(const char* fmt, const char* pretty_function, ...)
{
size_t len;
size_t len = 0;
const char* name = get_method_name(pretty_function, &len);

va_list args;
Expand Down
41 changes: 25 additions & 16 deletions Sming/Arch/Host/Components/hostlib/keyb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,14 @@
#include <fcntl.h>
#include <termios.h>

static bool g_orig_values_saved, g_values_changed;
static struct termios g_orig_attr;
static int g_orig_flags;
namespace
{
bool g_orig_values_saved;
bool g_values_changed;
struct termios g_orig_attr;
int g_orig_flags;

} // namespace

#endif

Expand All @@ -62,9 +67,9 @@ class CKeycode
int add(int c);

private:
char m_esc;
char m_buffer[32];
unsigned m_count;
char m_esc{};
char m_buffer[32]{};
unsigned m_count{};

void push(char c)
{
Expand Down Expand Up @@ -228,14 +233,16 @@ int CKeycode::add(int c)
void keyb_restore()
{
#ifndef __WIN32
if(g_values_changed) {
static struct termios attr = g_orig_attr;
attr.c_lflag |= ICANON | ECHO;
tcsetattr(STDIN_FILENO, TCSANOW, &attr);

(void)fcntl(0, F_SETFL, g_orig_flags);
g_values_changed = false;
if(!g_values_changed) {
return;
}

static struct termios attr = g_orig_attr;
attr.c_lflag |= ICANON | ECHO;
tcsetattr(STDIN_FILENO, TCSANOW, &attr);

(void)fcntl(0, F_SETFL, g_orig_flags);
g_values_changed = false;
#endif
}

Expand Down Expand Up @@ -271,14 +278,16 @@ int getch()
int getkey()
{
static CKeycode kc;
int c;
int c = 0;
for(;;) {
c = getch();
if(c == KEY_NONE)
if(c == KEY_NONE) {
break;
}
c = kc.add(c);
if(c != KEY_NONE)
if(c != KEY_NONE) {
break;
}
}
return c;
}
Expand Down
8 changes: 4 additions & 4 deletions Sming/Arch/Host/Components/hostlib/sockets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,12 @@ std::string socket_strerror()
{
char buf[256];
buf[0] = '\0';
int ErrorCode;
#ifdef __WIN32
ErrorCode = WSAGetLastError();
int ErrorCode = WSAGetLastError();
FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_ARGUMENT_ARRAY, nullptr,
ErrorCode, 0, buf, sizeof(buf), nullptr);
#else
ErrorCode = errno;
int ErrorCode = errno;
char* res = strerror_r(ErrorCode, buf, sizeof(buf));
if(res == nullptr) {
strcpy(buf, "Unknown");
Expand Down Expand Up @@ -438,7 +437,8 @@ CSocket* CServerSocket::try_connect()
return nullptr;
}

struct sockaddr sa;
struct sockaddr sa {
};
host_socklen_t len = sizeof(sa);
int fd = ::accept(m_fd, &sa, &len);
if(fd < 0) {
Expand Down
6 changes: 3 additions & 3 deletions Sming/Arch/Host/Components/hostlib/sockets.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class CSockAddr
struct sockaddr sa;
struct sockaddr_in in4; // AF_INET
struct sockaddr_in6 in6; // AF_INET6
} m_addr;
} m_addr{};

public:
CSockAddr()
Expand Down Expand Up @@ -213,7 +213,7 @@ class CSocketList : public std::vector<CSocket*>
class CServerSocket : public CSocket
{
public:
CServerSocket(int type = SOCK_STREAM) : CSocket(type), m_max_connections(1)
CServerSocket(int type = SOCK_STREAM) : CSocket(type)
{
}

Expand All @@ -240,6 +240,6 @@ class CServerSocket : public CSocket
}

private:
unsigned m_max_connections;
unsigned m_max_connections{1};
CSocketList m_clients;
};
17 changes: 9 additions & 8 deletions Sming/Arch/Host/Components/hostlib/startup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ static size_t parse_flash_size(const char* str)
if(str == nullptr) {
return 0;
}
char* tail;
char* tail = nullptr;
long res = strtol(str, &tail, 0);
if(res < 0) {
return 0;
Expand Down Expand Up @@ -132,21 +132,22 @@ int main(int argc, char* argv[])
struct Config {
int pause{-1};
int exitpause{-1};
int loopcount;
uint8_t cpulimit;
bool initonly;
int loopcount{};
uint8_t cpulimit{};
bool initonly{};
bool enable_network{true};
UartServer::Config uart;
FlashmemConfig flash;
UartServer::Config uart{};
FlashmemConfig flash{};
#ifndef DISABLE_NETWORK
struct lwip_param lwip;
struct lwip_param lwip {
};
#endif
};
static Config config{};

int uart_num{-1};
option_tag_t opt;
const char* arg;
const char* arg = nullptr;
while((opt = get_option(argc, argv, arg)) != opt_none) {
switch(opt) {
case opt_help:
Expand Down
3 changes: 2 additions & 1 deletion Sming/Arch/Host/Components/hostlib/threads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ void CMutex::unlock()

bool CSemaphore::timedwait(unsigned us)
{
struct timespec ts;
struct timespec ts {
};
clock_gettime(CLOCK_REALTIME, &ts);
uint64_t ns = ts.tv_nsec + uint64_t(us) * 1000;
ts.tv_sec += ns / 1000000000;
Expand Down
2 changes: 1 addition & 1 deletion Sming/Arch/Host/Components/hostlib/threads.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class CSemaphore
}

private:
sem_t m_sem;
sem_t m_sem{};
};

/**
Expand Down
2 changes: 1 addition & 1 deletion Sming/Arch/Host/Core/HardwarePWM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

#include <HardwarePWM.h>

HardwarePWM::HardwarePWM(uint8_t* pins, uint8_t no_of_pins) : channel_count(no_of_pins), maxduty(0)
HardwarePWM::HardwarePWM(uint8_t* pins, uint8_t no_of_pins) : channel_count(no_of_pins)
{
}

Expand Down
6 changes: 4 additions & 2 deletions Sming/Arch/Host/Platform/RTC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,17 @@ RtcClass::RtcClass()

uint64_t RtcClass::getRtcNanoseconds()
{
struct timeval tv;
struct timeval tv {
};
gettimeofday(&tv, nullptr);
uint64_t usecs = (tv.tv_sec * 1000000ULL) + (uint32_t)tv.tv_usec;
return usecs * 1000;
}

uint32_t RtcClass::getRtcSeconds()
{
struct timeval tv;
struct timeval tv {
};
gettimeofday(&tv, nullptr);
return tv.tv_sec + timeDiff;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ class TcpServerTransport : public TcpTransport
if(stream == nullptr) {
map[key] = stream = new TcpClientStream(client);
client.setReceiveDelegate(TcpClientDataDelegate(&TcpServerTransport::process, this));
stream = map[key];
}

if(!stream->push(reinterpret_cast<const uint8_t*>(data), size)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@ Base64OutputStream::Base64OutputStream(IDataSourceStream* stream, size_t resultS

size_t Base64OutputStream::transform(const uint8_t* source, size_t sourceLength, uint8_t* target, size_t targetLength)
{
size_t count;
if(sourceLength == 0) {
count = base64_encode_blockend((char*)target, &state);
} else {
count = base64_encode_block((const char*)source, sourceLength, (char*)target, &state);
return base64_encode_blockend(reinterpret_cast<char*>(target), &state);
}

return count;
return base64_encode_block(reinterpret_cast<const char*>(source), sourceLength, reinterpret_cast<char*>(target),
&state);
}
6 changes: 2 additions & 4 deletions Sming/Components/Network/src/IpAddress.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,12 @@ class IpAddress
ip_addr_set_ip4_u32(&this->address, address);
}

IpAddress(ip_addr_t& addr)
IpAddress(ip_addr_t& addr) : address(addr)
{
address = addr;
}

IpAddress(const ip_addr_t& addr)
IpAddress(const ip_addr_t& addr) : address(addr)
{
address = addr;
}

#if LWIP_VERSION_MAJOR == 2 && LWIP_IPV6
Expand Down
3 changes: 1 addition & 2 deletions Sming/Components/Network/src/Network/Http/HttpConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,7 @@ bool HttpConnection::isActive()
return false;
}

struct tcp_pcb* pcb;
for(pcb = tcp_active_pcbs; pcb != nullptr; pcb = pcb->next) {
for(auto pcb = tcp_active_pcbs; pcb != nullptr; pcb = pcb->next) {
if(tcp == pcb) {
return true;
}
Expand Down
Loading

0 comments on commit 4b9fc84

Please sign in to comment.