diff --git a/Sming/Arch/Esp8266/Components/driver/SerialBuffer.h b/Sming/Arch/Esp8266/Components/driver/SerialBuffer.h index f2df1f9a49..71a626c900 100644 --- a/Sming/Arch/Esp8266/Components/driver/SerialBuffer.h +++ b/Sming/Arch/Esp8266/Components/driver/SerialBuffer.h @@ -23,7 +23,7 @@ struct SerialBuffer { public: ~SerialBuffer() { - delete buffer; + delete[] buffer; } size_t getSize() diff --git a/Sming/Arch/Host/Components/driver/uart.cpp b/Sming/Arch/Host/Components/driver/uart.cpp index 9a215b3565..ee07fe2499 100644 --- a/Sming/Arch/Host/Components/driver/uart.cpp +++ b/Sming/Arch/Host/Components/driver/uart.cpp @@ -111,7 +111,7 @@ static bool realloc_buffer(SerialBuffer*& buffer, size_t new_size) { if(buffer != nullptr) { if(new_size == 0) { - uart_disable_interrupts(); + (void)uart_disable_interrupts(); delete buffer; buffer = nullptr; uart_restore_interrupts(); @@ -207,7 +207,7 @@ size_t uart_rx_available(uart_t* uart) return 0; } - uart_disable_interrupts(); + (void)uart_disable_interrupts(); size_t avail = 0; @@ -260,7 +260,7 @@ size_t uart_tx_free(uart_t* uart) return 0; } - uart_disable_interrupts(); + (void)uart_disable_interrupts(); size_t space = 0; if(uart->tx_buffer != nullptr) { @@ -324,7 +324,7 @@ void uart_flush(uart_t* uart, uart_mode_t mode) bool flushRx = mode != UART_TX_ONLY && uart->mode != UART_TX_ONLY; bool flushTx = mode != UART_RX_ONLY && uart->mode != UART_RX_ONLY; - uart_disable_interrupts(); + (void)uart_disable_interrupts(); if(flushRx && uart->rx_buffer != nullptr) { uart->rx_buffer->clear(); } diff --git a/Sming/Arch/Host/Components/hostlib/hostlib.c b/Sming/Arch/Host/Components/hostlib/hostlib.c index 0647390804..4fc60673c8 100644 --- a/Sming/Arch/Host/Components/hostlib/hostlib.c +++ b/Sming/Arch/Host/Components/hostlib/hostlib.c @@ -31,7 +31,7 @@ int msleep(unsigned ms) void getHostAppDir(char* path, size_t bufSize) { - size_t len __attribute__((unused)); + size_t len; char sep; #ifdef __WIN32 len = GetModuleFileName(NULL, path, bufSize); @@ -40,6 +40,7 @@ void getHostAppDir(char* path, size_t bufSize) len = readlink("/proc/self/exe", path, bufSize); sep = '/'; #endif + path[len] = '\0'; char* p = strrchr(path, sep); if(p) { p[1] = '\0'; diff --git a/Sming/Arch/Host/Components/hostlib/keyb.cpp b/Sming/Arch/Host/Components/hostlib/keyb.cpp index e59c5965e2..6106bca104 100644 --- a/Sming/Arch/Host/Components/hostlib/keyb.cpp +++ b/Sming/Arch/Host/Components/hostlib/keyb.cpp @@ -233,7 +233,7 @@ void keyb_restore() attr.c_lflag |= ICANON | ECHO; tcsetattr(STDIN_FILENO, TCSANOW, &attr); - fcntl(0, F_SETFL, g_orig_flags); + (void)fcntl(0, F_SETFL, g_orig_flags); g_values_changed = false; } #endif @@ -250,7 +250,7 @@ void keyb_raw() } // make stdin non-blocking - fcntl(0, F_SETFL, g_orig_flags | O_NONBLOCK); + (void)fcntl(0, F_SETFL, g_orig_flags | O_NONBLOCK); // struct termios attr = g_orig_attr; attr.c_lflag &= ~(ICANON | ECHO); diff --git a/Sming/Arch/Host/Components/hostlib/sockets.cpp b/Sming/Arch/Host/Components/hostlib/sockets.cpp index 72526beb74..6a56c10851 100644 --- a/Sming/Arch/Host/Components/hostlib/sockets.cpp +++ b/Sming/Arch/Host/Components/hostlib/sockets.cpp @@ -441,7 +441,7 @@ CSocket* CServerSocket::try_connect() struct sockaddr sa; socklen_t len = sizeof(sa); int fd = ::accept(m_fd, &sa, &len); - if(fd <= 0) { + if(fd < 0) { return nullptr; } diff --git a/Sming/Arch/Host/Components/hostlib/startup.cpp b/Sming/Arch/Host/Components/hostlib/startup.cpp index 35c4898bee..d25695ba25 100644 --- a/Sming/Arch/Host/Components/hostlib/startup.cpp +++ b/Sming/Arch/Host/Components/hostlib/startup.cpp @@ -94,7 +94,7 @@ static void pause(int secs) { if(secs == 0) { hostmsg("Hit ENTER to continue."); - getchar(); + (void)getchar(); } else if(secs > 0) { hostmsg("Waiting for %u seconds...", secs); msleep(secs * 1000); diff --git a/Sming/Arch/Host/Components/lwip/.patches/lwip.patch b/Sming/Arch/Host/Components/lwip/.patches/lwip.patch index 69c84e2c93..483d7850ac 100644 --- a/Sming/Arch/Host/Components/lwip/.patches/lwip.patch +++ b/Sming/Arch/Host/Components/lwip/.patches/lwip.patch @@ -1,8 +1,22 @@ diff --git a/contrib/ports/unix/port/sys_arch.c b/contrib/ports/unix/port/sys_arch.c -index a56d7de1..dd3f16e1 100644 +index a56d7de1..6fc9f434 100644 --- a/contrib/ports/unix/port/sys_arch.c +++ b/contrib/ports/unix/port/sys_arch.c -@@ -730,13 +730,3 @@ sys_arch_unprotect(sys_prot_t pval) +@@ -68,10 +68,12 @@ + #include "lwip/stats.h" + #include "lwip/tcpip.h" + ++extern u32_t os_random(void); ++ + u32_t + lwip_port_rand(void) + { +- return (u32_t)rand(); ++ return os_random(); + } + + static void +@@ -730,13 +732,3 @@ sys_arch_unprotect(sys_prot_t pval) } #endif /* SYS_LIGHTWEIGHT_PROT */ diff --git a/Sming/Arch/Host/Components/lwip/Linux/host_lwip.c b/Sming/Arch/Host/Components/lwip/Linux/host_lwip.c index 3c09929244..9ec7255be3 100644 --- a/Sming/Arch/Host/Components/lwip/Linux/host_lwip.c +++ b/Sming/Arch/Host/Components/lwip/Linux/host_lwip.c @@ -49,13 +49,17 @@ static void getMacAddress(const char* ifname, uint8_t hwaddr[6]) { struct ifreq ifr = {0}; ifr.ifr_addr.sa_family = AF_INET; - strcpy(ifr.ifr_name, ifname); + strncpy(ifr.ifr_name, ifname, IFNAMSIZ); int fd = socket(AF_INET, SOCK_DGRAM, 0); - ioctl(fd, SIOCGIFHWADDR, &ifr); + int res = ioctl(fd, SIOCGIFHWADDR, &ifr); close(fd); - memcpy(hwaddr, ifr.ifr_hwaddr.sa_data, 6); + if(res == 0) { + memcpy(hwaddr, ifr.ifr_hwaddr.sa_data, 6); + } else { + memset(hwaddr, 0, 6); + } } /** @@ -127,7 +131,7 @@ bool host_lwip_init(const struct lwip_param* param) if(param->ipaddr == NULL) { // Choose a default IP address - IP4_ADDR(&netcfg.ipaddr, ip4_addr1(&netcfg.gw), ip4_addr2(&netcfg.gw), ip4_addr3(&netcfg.gw), 10); + IP4_ADDR(&netcfg.ipaddr, (uint32_t)ip4_addr1(&netcfg.gw), (uint32_t)ip4_addr2(&netcfg.gw), (uint32_t)ip4_addr3(&netcfg.gw), 10U); } else if(ip4addr_aton(param->ipaddr, &netcfg.ipaddr) != 1) { hostmsg("Failed to parse provided IP address '%s'", param->ipaddr); return false; diff --git a/Sming/Arch/Host/Components/spi_flash/flashmem.cpp b/Sming/Arch/Host/Components/spi_flash/flashmem.cpp index 188dd827bc..e56480705b 100644 --- a/Sming/Arch/Host/Components/spi_flash/flashmem.cpp +++ b/Sming/Arch/Host/Components/spi_flash/flashmem.cpp @@ -39,10 +39,10 @@ static const char* defaultFlashFileName = "flash.bin"; bool host_flashmem_init(FlashmemConfig& config) { if(config.filename != nullptr) { - strcpy(flashFileName, config.filename); + strncpy(flashFileName, config.filename, sizeof(flashFileName)); } else { getHostAppDir(flashFileName, sizeof(flashFileName)); - strcat(flashFileName, defaultFlashFileName); + strcpy(flashFileName, defaultFlashFileName); config.filename = flashFileName; } diff --git a/Sming/Arch/Host/Core/DigitalHooks.cpp b/Sming/Arch/Host/Core/DigitalHooks.cpp index bed86d9aae..8e25cad702 100644 --- a/Sming/Arch/Host/Core/DigitalHooks.cpp +++ b/Sming/Arch/Host/Core/DigitalHooks.cpp @@ -40,6 +40,6 @@ void DigitalHooks::pullup(uint16_t pin, bool enable) unsigned long DigitalHooks::pulseIn(uint16_t pin, uint8_t state, unsigned long timeout) { - host_printfp("pin: %u, state: %u, timeout: %u\n", __FUNCTION__, pin, state, timeout); + host_printfp("pin: %u, state: %u, timeout: %lu\n", __FUNCTION__, pin, state, timeout); return 0; } diff --git a/Sming/Arch/Host/Core/HardwarePWM.cpp b/Sming/Arch/Host/Core/HardwarePWM.cpp index b974970e21..876e6f2fee 100644 --- a/Sming/Arch/Host/Core/HardwarePWM.cpp +++ b/Sming/Arch/Host/Core/HardwarePWM.cpp @@ -25,7 +25,7 @@ #include -HardwarePWM::HardwarePWM(uint8_t* pins, uint8_t no_of_pins) : channel_count(no_of_pins) +HardwarePWM::HardwarePWM(uint8_t* pins, uint8_t no_of_pins) : channel_count(no_of_pins), maxduty(0) { } diff --git a/Sming/Components/.patches/ws_parser.patch b/Sming/Components/.patches/ws_parser.patch index c7fc5bf08e..c1bfd3aba0 100644 --- a/Sming/Components/.patches/ws_parser.patch +++ b/Sming/Components/.patches/ws_parser.patch @@ -1,8 +1,24 @@ diff --git a/ws_parser.c b/ws_parser.c -index 88e4810..3da68e1 100644 +index 88e4810..e2d1147 100644 --- a/ws_parser.c +++ b/ws_parser.c -@@ -244,7 +244,8 @@ ws_parser_execute(ws_parser_t* parser, /* mutates! */ char* buff, size_t len) +@@ -3,6 +3,7 @@ + #endif + + #include "ws_parser.h" ++#include + + enum { + S_OPCODE = 0, +@@ -27,6 +28,7 @@ enum { + void + ws_parser_init(ws_parser_t* parser, const ws_parser_callbacks_t* callbacks) + { ++ memset(parser, 0, sizeof(ws_parser_t)); + parser->user_data = NULL; + parser->callbacks = callbacks; + parser->state = S_OPCODE; +@@ -244,7 +246,8 @@ ws_parser_execute(ws_parser_t* parser, /* mutates! */ char* buff, size_t len) } if(parser->mask_flag) { diff --git a/Sming/Core/Data/Stream/FileStream.cpp b/Sming/Core/Data/Stream/FileStream.cpp index c1d5be82e6..a5ddbee884 100644 --- a/Sming/Core/Data/Stream/FileStream.cpp +++ b/Sming/Core/Data/Stream/FileStream.cpp @@ -63,10 +63,10 @@ uint16_t FileStream::readMemoryBlock(char* data, int bufSize) } int available = fileRead(handle, data, std::min(size - pos, size_t(bufSize))); - check(available); + (void)check(available); // Don't move cursor now (waiting seek) - fileSeek(handle, pos, eSO_FileStart); + (void)fileSeek(handle, pos, eSO_FileStart); return available > 0 ? available : 0; } diff --git a/Sming/Core/Data/Stream/GdbFileStream.cpp b/Sming/Core/Data/Stream/GdbFileStream.cpp index a0721524a5..8ff135ac0a 100644 --- a/Sming/Core/Data/Stream/GdbFileStream.cpp +++ b/Sming/Core/Data/Stream/GdbFileStream.cpp @@ -74,10 +74,10 @@ uint16_t GdbFileStream::readMemoryBlock(char* data, int bufSize) } int available = gdb_syscall_read(handle, data, std::min(size - pos, size_t(bufSize))); - check(available); + (void)check(available); // Don't move cursor now (waiting seek) - gdb_syscall_lseek(handle, pos, SEEK_SET); + (void)gdb_syscall_lseek(handle, pos, SEEK_SET); return available > 0 ? available : 0; } diff --git a/Sming/Core/HardwareSerial.cpp b/Sming/Core/HardwareSerial.cpp index ca2ba52ef7..952266ac19 100644 --- a/Sming/Core/HardwareSerial.cpp +++ b/Sming/Core/HardwareSerial.cpp @@ -105,7 +105,7 @@ void HardwareSerial::systemDebugOutput(bool enabled) void HardwareSerial::invokeCallbacks() { - uart_disable_interrupts(); + (void)uart_disable_interrupts(); auto status = callbackStatus; callbackStatus = 0; callbackQueued = false;