forked from qt-creator/qt-creator
QML/JS: fix improbable nullptr deref in possible future use.
The ast parameter cannot be null, because the only use checks for it not to be null. However, if it would ever be re-used somewhere else, the logic is plain wrong. Clarification by an assert makes it clear what the intent is. Pointed out by the clang static analyzer. Change-Id: I2c8cba5e5847fc1f92c10021109c55ff8ccd58c4 Reviewed-by: Fawzi Mohamed <fawzi.mohamed@digia.com>
This commit is contained in:
@@ -36,6 +36,8 @@
|
|||||||
#include "qmljsinterpreter.h"
|
#include "qmljsinterpreter.h"
|
||||||
#include "qmljsutils.h"
|
#include "qmljsutils.h"
|
||||||
|
|
||||||
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
|
||||||
using namespace QmlJS;
|
using namespace QmlJS;
|
||||||
@@ -418,7 +420,9 @@ void TypeDescriptionReader::readParameter(UiObjectDefinition *ast, FakeMetaMetho
|
|||||||
|
|
||||||
QString TypeDescriptionReader::readStringBinding(UiScriptBinding *ast)
|
QString TypeDescriptionReader::readStringBinding(UiScriptBinding *ast)
|
||||||
{
|
{
|
||||||
if (!ast || !ast->statement) {
|
QTC_ASSERT(ast, return QString());
|
||||||
|
|
||||||
|
if (!ast->statement) {
|
||||||
addError(ast->colonToken, tr("Expected string after colon."));
|
addError(ast->colonToken, tr("Expected string after colon."));
|
||||||
return QString();
|
return QString();
|
||||||
}
|
}
|
||||||
@@ -440,7 +444,9 @@ QString TypeDescriptionReader::readStringBinding(UiScriptBinding *ast)
|
|||||||
|
|
||||||
bool TypeDescriptionReader::readBoolBinding(AST::UiScriptBinding *ast)
|
bool TypeDescriptionReader::readBoolBinding(AST::UiScriptBinding *ast)
|
||||||
{
|
{
|
||||||
if (!ast || !ast->statement) {
|
QTC_ASSERT(ast, return false);
|
||||||
|
|
||||||
|
if (!ast->statement) {
|
||||||
addError(ast->colonToken, tr("Expected boolean after colon."));
|
addError(ast->colonToken, tr("Expected boolean after colon."));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -463,7 +469,9 @@ bool TypeDescriptionReader::readBoolBinding(AST::UiScriptBinding *ast)
|
|||||||
|
|
||||||
double TypeDescriptionReader::readNumericBinding(AST::UiScriptBinding *ast)
|
double TypeDescriptionReader::readNumericBinding(AST::UiScriptBinding *ast)
|
||||||
{
|
{
|
||||||
if (!ast || !ast->statement) {
|
QTC_ASSERT(ast, return qQNaN());
|
||||||
|
|
||||||
|
if (!ast->statement) {
|
||||||
addError(ast->colonToken, tr("Expected numeric literal after colon."));
|
addError(ast->colonToken, tr("Expected numeric literal after colon."));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -522,7 +530,9 @@ int TypeDescriptionReader::readIntBinding(AST::UiScriptBinding *ast)
|
|||||||
|
|
||||||
void TypeDescriptionReader::readExports(UiScriptBinding *ast, FakeMetaObject::Ptr fmo)
|
void TypeDescriptionReader::readExports(UiScriptBinding *ast, FakeMetaObject::Ptr fmo)
|
||||||
{
|
{
|
||||||
if (!ast || !ast->statement) {
|
QTC_ASSERT(ast, return);
|
||||||
|
|
||||||
|
if (!ast->statement) {
|
||||||
addError(ast->colonToken, tr("Expected array of strings after colon."));
|
addError(ast->colonToken, tr("Expected array of strings after colon."));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -566,7 +576,9 @@ void TypeDescriptionReader::readExports(UiScriptBinding *ast, FakeMetaObject::Pt
|
|||||||
|
|
||||||
void TypeDescriptionReader::readMetaObjectRevisions(UiScriptBinding *ast, FakeMetaObject::Ptr fmo)
|
void TypeDescriptionReader::readMetaObjectRevisions(UiScriptBinding *ast, FakeMetaObject::Ptr fmo)
|
||||||
{
|
{
|
||||||
if (!ast || !ast->statement) {
|
QTC_ASSERT(ast, return);
|
||||||
|
|
||||||
|
if (!ast->statement) {
|
||||||
addError(ast->colonToken, tr("Expected array of numbers after colon."));
|
addError(ast->colonToken, tr("Expected array of numbers after colon."));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user