From a1cbca44ef40d89f1ff9182e4014f9b8594330d5 Mon Sep 17 00:00:00 2001 From: Timur Pocheptsov Date: Mon, 7 Sep 2020 08:24:59 +0200 Subject: [PATCH] TLS utils - move runtime check to compile time MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit While it's possible to instantiate safe_delete using a nullptr, the check in if-statement is 99.9(9) % of time redundant and equal to if (true && object). Some compilers will issue a compilation error (if warnings are treated as errors for example). Change-Id: Ib593dc53deb6d2e4b77ea5c896610dc536c61b7c Reviewed-by: MÃ¥rten Nordheim --- src/network/ssl/qtls_utils_p.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/network/ssl/qtls_utils_p.h b/src/network/ssl/qtls_utils_p.h index 6777c1cbdbd..ceca3030d62 100644 --- a/src/network/ssl/qtls_utils_p.h +++ b/src/network/ssl/qtls_utils_p.h @@ -72,14 +72,18 @@ namespace QTlslUtils template void safe_delete(NativeTlsType *object) { - if (object && Deleter) + static_assert (Deleter, "safe_delete: invalid (nullptr) function pointer provided"); + + if (object) Deleter(object); } template void safe_delete(NativeTlsType *object) { - if (Deleter && object) { + static_assert (Deleter, "safe_delete: invalid (nullptr) function pointer provided"); + + if (object) { if (Deleter(object) != ok) { qCWarning(lcSsl, "Failed to free a resource."); #if QT_CONFIG(openssl) // || wolfssl later