summaryrefslogtreecommitdiffstats
path: root/src/network
diff options
context:
space:
mode:
authorTimur Pocheptsov <timur.pocheptsov@qt.io>2020-09-07 08:24:59 +0200
committerTimur Pocheptsov <timur.pocheptsov@qt.io>2020-09-09 21:53:37 +0200
commita1cbca44ef40d89f1ff9182e4014f9b8594330d5 (patch)
tree9938a4ca413b479c483a540999fec0ebd5703c6c /src/network
parent3247f01c5e185eed99113d92c1c2af0f2e068ba4 (diff)
TLS utils - move runtime check to compile time
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 <marten.nordheim@qt.io>
Diffstat (limited to 'src/network')
-rw-r--r--src/network/ssl/qtls_utils_p.h8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/network/ssl/qtls_utils_p.h b/src/network/ssl/qtls_utils_p.h
index 6777c1cbdb..ceca3030d6 100644
--- a/src/network/ssl/qtls_utils_p.h
+++ b/src/network/ssl/qtls_utils_p.h
@@ -72,14 +72,18 @@ namespace QTlslUtils
template <class NativeTlsType, void (*Deleter)(NativeTlsType *)>
void safe_delete(NativeTlsType *object)
{
- if (object && Deleter)
+ static_assert (Deleter, "safe_delete: invalid (nullptr) function pointer provided");
+
+ if (object)
Deleter(object);
}
template<class NativeTlsType, int ok, int (*Deleter)(NativeTlsType *)>
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