qxmpp-project / qxmpp

Cross-platform C++ XMPP client and server library
408 stars 197 forks source link

The value '-1' is out of range of enum values. This causes unspecified or undefined behavior. #495

Closed nmariusp closed 1 year ago

nmariusp commented 1 year ago

I use git commit 88812716073e5f6941843a6f0778319be889dd3b Some of the C++ source code static analysis issues triggered by the fact that you use "-1" as if it were "Optional" or a C# style nullable enum. E.g. by PVS-Studio. /home/n/kde/src/qxmpp/src/base/QXmppBitsOfBinaryContentId.cpp:115: warning: V547 Expression 'int (algo) == - 1' is always false. /home/n/kde/src/qxmpp/src/base/QXmppDataForm.cpp:39: warning: V1016 The value '-1' is out of range of enum values. This causes unspecified or undefined behavior. /home/n/kde/src/qxmpp/src/base/QXmppStanza.cpp:407: warning: V1016 The value '-1' is out of range of enum values. This causes unspecified or undefined behavior. /home/n/kde/src/qxmpp/src/base/QXmppStanza.cpp:431: warning: V547 Expression 'int (cond) < 0' is always false. /home/n/kde/src/qxmpp/src/base/QXmppStanza.cpp:459: warning: V1016 The value '-1' is out of range of enum values. This causes unspecified or undefined behavior. /home/n/kde/src/qxmpp/src/base/QXmppStanza.cpp:503: warning: V547 Expression 'int (type) < 0' is always false. /home/n/kde/src/qxmpp/src/client/QXmppPubSubManager.cpp:964: warning: V785 Constant expression in switch statement. https://pvs-studio.com/en/docs/warnings/v1016/

lnjX commented 1 year ago

This is a known issue. We should probably add enumerators for -1.