Skip to content

Commit

Permalink
Fix GH#24704: ensure xml parse can cope with comments after empty notes
Browse files Browse the repository at this point in the history
Backport of musescore#24709, the only relevant part for Mu3, a memory leak and an incorrect logic for logging an error, both in importmxmlpass2.cpp
  • Loading branch information
wizofaus authored and Jojo-Schmitz committed Dec 28, 2024
1 parent 2a34157 commit ef17789
Showing 1 changed file with 15 additions and 19 deletions.
34 changes: 15 additions & 19 deletions importexport/musicxml/importmxmlpass2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3018,7 +3018,7 @@ void MusicXMLParserPass2::staffDetails(const QString& partId, Measure* measure)

int staffIdx = _score->staffIdx(part) + n;

StringData* t = new StringData;
StringData stringData;
QString visible = _e.attributes().value("print-object").toString();
QString spacing = _e.attributes().value("print-spacing").toString();
if (visible == "no" ) {
Expand Down Expand Up @@ -3055,15 +3055,13 @@ void MusicXMLParserPass2::staffDetails(const QString& partId, Measure* measure)
// save staff lines for later
staffLines = _e.readElementText().toInt();
// for a TAB staff also resize the string table and init with zeroes
if (t) {
if (0 < staffLines)
t->stringList() = QVector<instrString>(staffLines).toList();
else
_logger->logError(QString("illegal staff-lines %1").arg(staffLines), &_e);
}
if (0 < staffLines)
stringData.stringList() = QVector<instrString>(staffLines).toList();
else
_logger->logError(QString("illegal staff-lines %1").arg(staffLines), &_e);
}
else if (_e.name() == "staff-tuning")
staffTuning(t);
staffTuning(&stringData);
else if (_e.name() == "staff-size") {
const double val = _e.readElementText().toDouble() / 100;
_score->staff(staffIdx)->setProperty(Pid::MAG, val);
Expand All @@ -3076,19 +3074,17 @@ void MusicXMLParserPass2::staffDetails(const QString& partId, Measure* measure)
setStaffLines(_score, staffIdx, staffLines);
}

if (t) {
Instrument* i = part->instrument();
if (_score->staff(staffIdx)->isTabStaff(Fraction(0, 1))) {
if (i->stringData()->frets() == 0)
t->setFrets(25);
else
t->setFrets(i->stringData()->frets());
}
if (t->strings() > 0)
i->setStringData(*t);
Instrument* i = part->instrument();
if (_score->staff(staffIdx)->isTabStaff(Fraction(0, 1))) {
if (i->stringData()->frets() == 0)
stringData.setFrets(25);
else
_logger->logError("trying to change string data (not supported)", &_e);
stringData.setFrets(i->stringData()->frets());
}
if (stringData.strings() > 0)
i->setStringData(stringData);
else if (stringData.strings() > 0)
_logger->logError("trying to change string data for non-TAB staff (not supported)", &_e);
}
//---------------------------------------------------------
// staffTuning
Expand Down

0 comments on commit ef17789

Please sign in to comment.