diff options
| author | Linus Jahn <lnj@kaidan.im> | 2022-12-28 20:35:34 +0100 |
|---|---|---|
| committer | Linus Jahn <lnj@kaidan.im> | 2022-12-28 20:38:05 +0100 |
| commit | 5365018c35e0a496376bde9bf7e4bb4e9df6de2a (patch) | |
| tree | 4eed5a451af86a0b5693bc8a90fa1aa99678048c /src | |
| parent | 4f0a029070091d11ab3d2e17e30e39b4476105e5 (diff) | |
StanzaError: Add NoType and NoCondition for -1 values
Previsously static_cast<QXmppStanza::Error::Condition>(-1) was used when
no condition was set (or type). This adds real enum values with that
integer value to avoid undefined behaviour.
Fixes #495.
Diffstat (limited to 'src')
| -rw-r--r-- | src/base/QXmppStanza.cpp | 13 | ||||
| -rw-r--r-- | src/base/QXmppStanza.h | 2 |
2 files changed, 8 insertions, 7 deletions
diff --git a/src/base/QXmppStanza.cpp b/src/base/QXmppStanza.cpp index e7cb0208..fa170740 100644 --- a/src/base/QXmppStanza.cpp +++ b/src/base/QXmppStanza.cpp @@ -399,12 +399,12 @@ void QXmppStanza::Error::setCode(int code) /// The conditions QXmppStanza::Error::Gone and QXmppStanza::Error::Redirect /// can be used in combination with redirectUri(). /// -/// \warning Due to compatibility this returns \c Condition(-1) when no -/// condition is set. When possible you should use conditionOpt(). +/// \warning This returns NoCondition when no condition is set. When possible you should use +/// conditionOpt(). /// QXmppStanza::Error::Condition QXmppStanza::Error::condition() const { - return d->condition.value_or(QXmppStanza::Error::Condition(-1)); + return d->condition.value_or(NoCondition); } /// @@ -426,7 +426,7 @@ auto QXmppStanza::Error::conditionOpt() const -> std::optional<Condition> /// The conditions QXmppStanza::Error::Gone and QXmppStanza::Error::Redirect /// can be used in combination with setRedirectUri(). /// -void QXmppStanza::Error::setCondition(QXmppStanza::Error::Condition cond) +void QXmppStanza::Error::setCondition(Condition cond) { if (int(cond) < 0) { d->condition = std::nullopt; @@ -451,12 +451,11 @@ void QXmppStanza::Error::setCondition(std::optional<Condition> cond) /// /// Returns the type of the error. /// -/// \warning Due to compatibility this returns \c Type(-1) when no type is set. -/// When possible you should use typeOpt(). +/// \warning This returns NoType when no type is set. When possible you should use typeOpt(). /// QXmppStanza::Error::Type QXmppStanza::Error::type() const { - return d->type.value_or(QXmppStanza::Error::Type(-1)); + return d->type.value_or(NoType); } /// diff --git a/src/base/QXmppStanza.h b/src/base/QXmppStanza.h index 394bc6c6..320bab26 100644 --- a/src/base/QXmppStanza.h +++ b/src/base/QXmppStanza.h @@ -98,6 +98,7 @@ public: /// The error descriptions are not detailed in here. The exact meaning /// can be found in the particular protocols using them. enum Type { + NoType = -1, Cancel, ///< The error is not temporary. Continue, ///< The error was only a warning. Modify, ///< The request needs to be changed and resent. @@ -107,6 +108,7 @@ public: /// A detailed condition of the error enum Condition { + NoCondition = -1, BadRequest, ///< The request does not contain a valid schema. Conflict, ///< The request conflicts with another. FeatureNotImplemented, ///< The feature is not implemented. |
