From 260517b7ba4e0bd0407bf9b9b464d43c9af32e7d Mon Sep 17 00:00:00 2001 From: garak Date: Wed, 11 Jan 2023 09:38:48 -0500 Subject: [PATCH] fix const for dynamic regular expressions --- src/core/parseutil.cpp | 48 ++++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/src/core/parseutil.cpp b/src/core/parseutil.cpp index 0f551bf3..363a835f 100644 --- a/src/core/parseutil.cpp +++ b/src/core/parseutil.cpp @@ -260,14 +260,14 @@ QString ParseUtil::readCIncbin(const QString &filename, const QString &label) { this->text = readTextFile(this->root + "/" + filename); - static const QRegularExpression re(QString( - "\\b%1\\b" - "\\s*\\[?\\s*\\]?\\s*=\\s*" - "INCBIN_[US][0-9][0-9]?" - "\\(\\s*\"([^\"]*)\"\\s*\\)").arg(label)); + int start = this->text.indexOf(label); + if (start < 0) return path; + int end = this->text.indexOf(';', start); + QString incbinText = this->text.mid(start, end - start); + static const QRegularExpression re_incbin("\\s*\\[?\\s*\\]?\\s*=\\s*INCBIN_[US][0-9][0-9]?\\(\\s*\\\"(?[^\\\"]*)\\\"\\s*\\)"); QRegularExpressionMatch match; - qsizetype pos = this->text.indexOf(re, 0, &match); + qsizetype pos = incbinText.indexOf(re_incbin, 0, &match); if (pos != -1) { path = match.captured(1); } @@ -284,15 +284,28 @@ QStringList ParseUtil::readCIncbinArray(const QString &filename, const QString & this->text = readTextFile(this->root + "/" + filename); + bool found = false; + QString arrayText; + // Get the text starting after the label all the way to the definition's end - static const QRegularExpression re_labelGroup(QString("\\b%1\\b(.*?)};").arg(label), QRegularExpression::DotMatchesEverythingOption); - QRegularExpressionMatch arrayMatch = re_labelGroup.match(this->text); - if (!arrayMatch.hasMatch()) + static const QRegularExpression re_labelGroup(QString("(?