summaryrefslogtreecommitdiffstats
path: root/src/tools/moc
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@woboq.com>2015-05-29 12:39:24 +0200
committerOlivier Goffart (Woboq GmbH) <ogoffart@woboq.com>2015-05-30 08:37:11 +0000
commit71c85c554a49ed3a17167e436630ddaff2b9fcb1 (patch)
tree8746bd76a0efbe91e5ce1ca596f5bea74b79204f /src/tools/moc
parent5b739a5b8cfbbedd9265b192d08b346d9b265590 (diff)
moc: Fix crash parsing invalid macro invocation
When invoking a macro with less argument than it expect, we would crash trying to access the vector of arguments from the invocation as we are trying to substitute an argument. (Note that we do not show an error in case of argument mismatch because ithat might happen parsing valid code as moc's c++ parser is not 100% accurate (that was QTBUG-29331)) Task-number: QTBUG-46210 Change-Id: I3f08d7f5049e593a5bdc02a594ea63cadf66e7a4 Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@theqtcompany.com>
Diffstat (limited to 'src/tools/moc')
-rw-r--r--src/tools/moc/preprocessor.cpp8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/tools/moc/preprocessor.cpp b/src/tools/moc/preprocessor.cpp
index 51873033c7..f253c49995 100644
--- a/src/tools/moc/preprocessor.cpp
+++ b/src/tools/moc/preprocessor.cpp
@@ -661,8 +661,10 @@ Symbols Preprocessor::macroExpandIdentifier(Preprocessor *that, SymbolStack &sym
expansion += s;
}
} else if (mode == Hash) {
- if (index < 0)
+ if (index < 0 || index >= arguments.size()) {
that->error("'#' is not followed by a macro parameter");
+ continue;
+ }
const Symbols &arg = arguments.at(index);
QByteArray stringified;
@@ -681,7 +683,7 @@ Symbols Preprocessor::macroExpandIdentifier(Preprocessor *that, SymbolStack &sym
expansion.pop_back();
Symbol next = s;
- if (index >= 0) {
+ if (index >= 0 && index < arguments.size()) {
const Symbols &arg = arguments.at(index);
if (arg.size() == 0) {
mode = Normal;
@@ -703,7 +705,7 @@ Symbols Preprocessor::macroExpandIdentifier(Preprocessor *that, SymbolStack &sym
expansion += next;
}
- if (index >= 0) {
+ if (index >= 0 && index < arguments.size()) {
const Symbols &arg = arguments.at(index);
for (int i = 1; i < arg.size(); ++i)
expansion += arg.at(i);