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>
This commit is contained in:
parent
3247f01c5e
commit
a1cbca44ef
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user