From 4c3928ecf4336da28316b2d646a7eda4208c5576 Mon Sep 17 00:00:00 2001 From: Mingjie Shen Date: Tue, 18 Apr 2023 23:12:39 -0400 Subject: [PATCH] Avoid calling virtual functions from constructors and destructors Virtual functions are resolved statically (not dynamically) in constructors and destructors for the same class. The call should be made explicitly static by qualifying it using the scope resolution operator. --- connectivity/netsocket/source/TLSSocketWrapper.cpp | 2 +- drivers/source/CAN.cpp | 4 ++-- drivers/source/SPI.cpp | 4 ++-- storage/filesystem/source/Dir.cpp | 2 +- storage/filesystem/source/File.cpp | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/connectivity/netsocket/source/TLSSocketWrapper.cpp b/connectivity/netsocket/source/TLSSocketWrapper.cpp index cebaf04703..29ee13271f 100644 --- a/connectivity/netsocket/source/TLSSocketWrapper.cpp +++ b/connectivity/netsocket/source/TLSSocketWrapper.cpp @@ -77,7 +77,7 @@ TLSSocketWrapper::TLSSocketWrapper(Socket *transport, const char *hostname, cont TLSSocketWrapper::~TLSSocketWrapper() { if (_transport) { - close(); + TLSSocketWrapper::close(); } mbedtls_entropy_free(&_entropy); diff --git a/drivers/source/CAN.cpp b/drivers/source/CAN.cpp index 6e5b149e11..07ea344d02 100644 --- a/drivers/source/CAN.cpp +++ b/drivers/source/CAN.cpp @@ -138,7 +138,7 @@ int CAN::filter(unsigned int id, unsigned int mask, CANFormat format, int handle void CAN::attach(Callback func, IrqType type) { - lock(); + CAN::lock(); if (func) { // lock deep sleep only the first time if (!_irq[(CanIrqType)type]) { @@ -154,7 +154,7 @@ void CAN::attach(Callback func, IrqType type) _irq[(CanIrqType)type] = nullptr; can_irq_set(&_can, (CanIrqType)type, 0); } - unlock(); + CAN::unlock(); } void CAN::_irq_handler(uintptr_t context, CanIrqType type) diff --git a/drivers/source/SPI.cpp b/drivers/source/SPI.cpp index cec9518fd0..76e2b74a53 100644 --- a/drivers/source/SPI.cpp +++ b/drivers/source/SPI.cpp @@ -148,12 +148,12 @@ void SPI::_do_construct() SPI::~SPI() { - lock(); + SPI::lock(); /* Make sure a stale pointer isn't left in peripheral's owner field */ if (_peripheral->owner == this) { _peripheral->owner = nullptr; } - unlock(); + SPI::unlock(); } SPI::spi_peripheral_s *SPI::_lookup(SPI::SPIName name) diff --git a/storage/filesystem/source/Dir.cpp b/storage/filesystem/source/Dir.cpp index 11602aa115..d659ad522d 100644 --- a/storage/filesystem/source/Dir.cpp +++ b/storage/filesystem/source/Dir.cpp @@ -34,7 +34,7 @@ Dir::Dir(FileSystem *fs, const char *path) Dir::~Dir() { if (_fs) { - close(); + Dir::close(); } } diff --git a/storage/filesystem/source/File.cpp b/storage/filesystem/source/File.cpp index 7355cb9243..49a1ef128a 100644 --- a/storage/filesystem/source/File.cpp +++ b/storage/filesystem/source/File.cpp @@ -34,7 +34,7 @@ File::File(FileSystem *fs, const char *path, int flags) File::~File() { if (_fs) { - close(); + File::close(); } }