Solved Why a warning on this line?
-
In this class method:
QStringList clsScriptHelper::slstJSON(const void* cpJson ,const QJsonValue::Type cType ,QString strRef ,uint8_t uint8Level ,uint8_t* puint8MaxLength) { QStringList slstKeys, slstResult; const QJsonArray* cparyJSON; const QJsonObject* cpobjJSON; int intSize; if ( cType == QJsonValue::Array ) { cparyJSON = static_cast<const QJsonArray*>(cpJson); cpobjJSON = nullptr; intSize = cparyJSON->size(); } if ( cType == QJsonValue::Object ) { cparyJSON = nullptr; cpobjJSON = static_cast<const QJsonObject*>(cpJson); slstKeys = cpobjJSON->keys(); intSize = slstKeys.size(); } if ( cparyJSON == nullptr && cpobjJSON == nullptr ) { //Invalid type, do nothing return slstResult; }
On the line:
if ( cparyJSON == nullptr && cpobjJSON == nullptr ) {
There is a yellow background and message to the right:
The left operand of '==' is a garbage value [clang-analyzer-core.UndefinedBinaryOperatorResult]
What does mean? I can't see anything wrong with the code itself.
-
@SPlatten said in Why a warning on this line?:
const QJsonArray* cparyJSON;
Because this pointer is not initialized and thus contains garbage (if none of the other if blocks is executed).
You should always initialize pointers when you declare them. -
@SPlatten said in Why a warning on this line?:
const QJsonArray* cparyJSON;
Because this pointer is not initialized and thus contains garbage (if none of the other if blocks is executed).
You should always initialize pointers when you declare them. -
Thank you.
-
This post is deleted!