From 9b134d6354089920d22c8de783093120c44cfb36 Mon Sep 17 00:00:00 2001 From: Alexander Lohnau Date: Sat, 9 Oct 2021 15:09:57 +0200 Subject: Enforce KAuthorized enums being not 0 This will output a warning if an invalid value is requested. The goal is to avoid implicit conversion which might result in a zero-int value. --- src/core/kauthorized.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/core/kauthorized.cpp') diff --git a/src/core/kauthorized.cpp b/src/core/kauthorized.cpp index 0c8beef9..aad23949 100644 --- a/src/core/kauthorized.cpp +++ b/src/core/kauthorized.cpp @@ -7,10 +7,12 @@ #include "kauthorized.h" +#include #include #include #include +#include "kconfig_core_log_settings.h" #include #include #include // srand(), rand() @@ -221,9 +223,11 @@ bool KAuthorized::authorize(const QString &genericAction) bool KAuthorized::authorize(KAuthorized::GenericRestriction action) { const QMetaEnum metaEnum = QMetaEnum::fromType(); - if (metaEnum.isValid()) { + + if (metaEnum.isValid() && action != 0) { return KAuthorized::authorize(QString::fromLatin1(metaEnum.valueToKey(action)).toLower()); } + qCWarning(KCONFIG_CORE_LOG) << "Invalid GenericRestriction requested" << action; return false; } @@ -243,9 +247,10 @@ bool KAuthorized::authorizeAction(const QString &action) bool KAuthorized::authorizeAction(KAuthorized::GenericAction action) { const QMetaEnum metaEnum = QMetaEnum::fromType(); - if (metaEnum.isValid()) { + if (metaEnum.isValid() && action != 0) { return KAuthorized::authorizeAction(QString::fromLatin1(metaEnum.valueToKey(action)).toLower()); } + qCWarning(KCONFIG_CORE_LOG) << "Invalid GenericAction requested" << action; return false; } -- cgit v1.2.1