diff options
author | Alexander Lohnau <alexander.lohnau@gmx.de> | 2021-10-09 15:09:57 +0200 |
---|---|---|
committer | Alexander Lohnau <alexander.lohnau@gmx.de> | 2021-10-13 12:59:30 +0000 |
commit | 9b134d6354089920d22c8de783093120c44cfb36 (patch) | |
tree | ff61c84ab5ad9181763c3950e77e15aae0fbf269 /src/core/kauthorized.cpp | |
parent | b0a3e4276e8318475c39c2b7b4b5bc4040dcd19e (diff) | |
download | kconfig-9b134d6354089920d22c8de783093120c44cfb36.tar.gz kconfig-9b134d6354089920d22c8de783093120c44cfb36.tar.bz2 |
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.
Diffstat (limited to 'src/core/kauthorized.cpp')
-rw-r--r-- | src/core/kauthorized.cpp | 9 |
1 files changed, 7 insertions, 2 deletions
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 <QDebug> #include <QDir> #include <QList> #include <QUrl> +#include "kconfig_core_log_settings.h" #include <QCoreApplication> #include <ksharedconfig.h> #include <stdlib.h> // srand(), rand() @@ -221,9 +223,11 @@ bool KAuthorized::authorize(const QString &genericAction) bool KAuthorized::authorize(KAuthorized::GenericRestriction action) { const QMetaEnum metaEnum = QMetaEnum::fromType<KAuthorized::GenericRestriction>(); - 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<KAuthorized::GenericAction>(); - 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; } |