From b2c4049d3f68e1ba44d227e9c0b425e690edcfcd Mon Sep 17 00:00:00 2001 From: developer79433 Date: Sun, 22 Dec 2024 16:24:34 +1100 Subject: [PATCH 1/3] Silence warning: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit external/OpenThings-Framework-Firmware-Library/LinuxLocalServer.cpp: In destructor ‘OTF::LinuxLocalServer::~LinuxLocalServer()’: external/OpenThings-Framework-Firmware-Library/LinuxLocalServer.cpp:9:3: warning: this ‘if’ clause does not guard... [-Wmisleading-indentation] 9 | if (activeClient != nullptr) | ^~ external/OpenThings-Framework-Firmware-Library/LinuxLocalServer.cpp:11:5: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘if’ 11 | delete activeClient; | ^~~~~~ --- LinuxLocalServer.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/LinuxLocalServer.cpp b/LinuxLocalServer.cpp index 3bbb902..471d339 100644 --- a/LinuxLocalServer.cpp +++ b/LinuxLocalServer.cpp @@ -6,9 +6,10 @@ using namespace OTF; LinuxLocalServer::LinuxLocalServer(uint16_t port) : server(port) {} LinuxLocalServer::~LinuxLocalServer() { - if (activeClient != nullptr) + if (activeClient != nullptr) { activeClient->stop(); delete activeClient; + } } @@ -72,4 +73,4 @@ void LinuxLocalClient::flush() { void LinuxLocalClient::stop() { client.stop(); } -#endif \ No newline at end of file +#endif From 3ec91bda56d4fdf474c9bf0dd75f7c81b296049e Mon Sep 17 00:00:00 2001 From: developer79433 Date: Sun, 22 Dec 2024 16:27:04 +1100 Subject: [PATCH 2/3] Give several classes virtual destructors, MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Silences several warnings, eg: external/OpenThings-Framework-Firmware-Library/LinuxLocalServer.cpp:11:5: warning: deleting object of polymorphic class type ‘OTF::LinuxLocalClient’ which has non-virtual destructor might cause undefined behavior [-Wdelete-non-virtual-dtor] 11 | delete activeClient; | ^~~~~~~~~~~~~~~~~~~ --- LinuxLocalServer.h | 5 +++-- LocalServer.h | 2 ++ etherport.h | 6 +++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/LinuxLocalServer.h b/LinuxLocalServer.h index 1756cf4..34a99aa 100644 --- a/LinuxLocalServer.h +++ b/LinuxLocalServer.h @@ -14,6 +14,7 @@ namespace OTF { LinuxLocalClient(EthernetClient client); public: + virtual ~LinuxLocalClient() {} bool dataAvailable(); size_t readBytes(char *buffer, size_t length); size_t readBytesUntil(char terminator, char *buffer, size_t length); @@ -33,7 +34,7 @@ namespace OTF { public: LinuxLocalServer(uint16_t port); - ~LinuxLocalServer(); + virtual ~LinuxLocalServer(); LocalClient *acceptClient(); void begin(); @@ -41,4 +42,4 @@ namespace OTF { }// namespace OTF #endif -#endif \ No newline at end of file +#endif diff --git a/LocalServer.h b/LocalServer.h index 9bee9ec..c6bdb0e 100644 --- a/LocalServer.h +++ b/LocalServer.h @@ -12,6 +12,7 @@ namespace OTF { class LocalClient { public: + virtual ~LocalClient() {}; /** Returns a boolean indicating if data is currently available from this client. */ virtual bool dataAvailable() = 0; @@ -50,6 +51,7 @@ namespace OTF { class LocalServer { public: + virtual ~LocalServer() {}; /** * Closes the active client (if one is active) and accepts a new client (if one is available). * @return The newly accepted client, or `nullptr` if none was available. diff --git a/etherport.h b/etherport.h index 444d188..f8a2e65 100644 --- a/etherport.h +++ b/etherport.h @@ -49,7 +49,7 @@ class EthernetClient { public: EthernetClient(); EthernetClient(int sock); - ~EthernetClient(); + virtual ~EthernetClient(); virtual int connect(const char *server, uint16_t port); virtual bool connected(); virtual void stop(); @@ -77,7 +77,7 @@ class EthernetClientSsl : public EthernetClient { public: EthernetClientSsl(); EthernetClientSsl(int sock); - ~EthernetClientSsl(); + virtual ~EthernetClientSsl(); virtual int connect(const char *server, uint16_t port); virtual bool connected(); virtual void stop(); @@ -101,4 +101,4 @@ class EthernetServer { }; #endif -#endif /* _ETHERPORT_H_ */ \ No newline at end of file +#endif /* _ETHERPORT_H_ */ From 4e28b69bcb867232fc28c588f7933f2b9bc22e89 Mon Sep 17 00:00:00 2001 From: developer79433 Date: Sun, 22 Dec 2024 16:29:36 +1100 Subject: [PATCH 3/3] Use size_t instead of int in several places. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Silences (eg when building OpenSprinkler): external/OpenThings-Framework-Firmware-Library/OpenThingsFramework.cpp: In member function ‘void OTF::OpenThingsFramework::localServerLoop()’: external/OpenThings-Framework-Firmware-Library/OpenThingsFramework.cpp:126:16: warning: comparison of integer expressions of different signedness: ‘size_t’ {aka ‘long unsigned int’} and ‘int’ [-Wsign-compare] 126 | if (length >= headerBufferSize) { | ~~~~~~~^~~~~~~~~~~~~~~~~~~ --- OpenThingsFramework.cpp | 6 +++--- OpenThingsFramework.h | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/OpenThingsFramework.cpp b/OpenThingsFramework.cpp index 0e3f95a..b9cc53f 100755 --- a/OpenThingsFramework.cpp +++ b/OpenThingsFramework.cpp @@ -11,7 +11,7 @@ using namespace OTF; -OpenThingsFramework::OpenThingsFramework(uint16_t webServerPort, char *hdBuffer, int hdBufferSize) : localServer(webServerPort) { +OpenThingsFramework::OpenThingsFramework(uint16_t webServerPort, char *hdBuffer, size_t hdBufferSize) : localServer(webServerPort) { OTF_DEBUG("Instantiating OTF...\n"); if(hdBuffer != NULL) { // if header buffer is externally provided, use it directly headerBuffer = hdBuffer; @@ -26,10 +26,10 @@ OpenThingsFramework::OpenThingsFramework(uint16_t webServerPort, char *hdBuffer, #if defined(ARDUINO) OpenThingsFramework::OpenThingsFramework(uint16_t webServerPort, const String &webSocketHost, uint16_t webSocketPort, - const String &deviceKey, bool useSsl, char *hdBuffer, int hdBufferSize) : OpenThingsFramework(webServerPort, hdBuffer, hdBufferSize) { + const String &deviceKey, bool useSsl, char *hdBuffer, size_t hdBufferSize) : OpenThingsFramework(webServerPort, hdBuffer, hdBufferSize) { #else OpenThingsFramework::OpenThingsFramework(uint16_t webServerPort, const char* webSocketHost, uint16_t webSocketPort, - const char* deviceKey, bool useSsl, char *hdBuffer, int hdBufferSize) : OpenThingsFramework(webServerPort, hdBuffer, hdBufferSize) { + const char* deviceKey, bool useSsl, char *hdBuffer, size_t hdBufferSize) : OpenThingsFramework(webServerPort, hdBuffer, hdBufferSize) { #endif setCloudStatus(UNABLE_TO_CONNECT); OTF_DEBUG(F("Initializing websocket...\n")); diff --git a/OpenThingsFramework.h b/OpenThingsFramework.h index cc338a3..8da32b2 100644 --- a/OpenThingsFramework.h +++ b/OpenThingsFramework.h @@ -63,7 +63,7 @@ namespace OTF { CLOUD_STATUS cloudStatus = NOT_ENABLED; unsigned long lastCloudStatusChangeTime = millis(); char *headerBuffer = NULL; - int headerBufferSize = 0; + size_t headerBufferSize = 0; void webSocketEventCallback(WSEvent_t type, uint8_t *payload, size_t length); @@ -80,7 +80,7 @@ namespace OTF { * @param hdBuffer externally provided header buffer (optional) * @param hdBufferSize size of the externally provided header buffer (optional) */ - OpenThingsFramework(uint16_t webServerPort, char *hdBuffer = NULL, int hdBufferSize = HEADERS_BUFFER_SIZE); + OpenThingsFramework(uint16_t webServerPort, char *hdBuffer = NULL, size_t hdBufferSize = HEADERS_BUFFER_SIZE); /** * Initializes the library to listen on a local webserver and connect to a remote websocket. @@ -94,10 +94,10 @@ namespace OTF { */ #if defined(ARDUINO) OpenThingsFramework(uint16_t webServerPort, const String &webSocketHost, uint16_t webSocketPort, - const String &deviceKey, bool useSsl, char *hdBuffer = NULL, int hdBufferSize = HEADERS_BUFFER_SIZE); + const String &deviceKey, bool useSsl, char *hdBuffer = NULL, size_t hdBufferSize = HEADERS_BUFFER_SIZE); #else OpenThingsFramework(uint16_t webServerPort, const char *webSocketHost, uint16_t webSocketPort, - const char *deviceKey, bool useSsl, char *hdBuffer = NULL, int hdBufferSize = HEADERS_BUFFER_SIZE); + const char *deviceKey, bool useSsl, char *hdBuffer = NULL, size_t hdBufferSize = HEADERS_BUFFER_SIZE); #endif /**