Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MU3] Fix printing user errors in musescore.cpp #7118

Merged
merged 1 commit into from Dec 22, 2020

Conversation

orivej
Copy link
Contributor

@orivej orivej commented Dec 19, 2020

Resolves: #6914 (comment)

v3.6_public_beta fails to build with Nixpkgs because by default it enables -Wformat -Wformat-security -Werror=format-security, which does not accept qFatal(qUtf8Printable(tr("…"))). This fixes it by replacing qFatal with fprintf. (See also commit description.)

  • I signed CLA
  • I made sure the code in the PR follows the coding rules
  • I made sure the code compiles on my machine
  • I made sure there are no unnecessary changes in the code
  • I made sure the title of the PR reflects the core meaning of the issue you are solving
  • I made sure the commit message(s) contain a description and answer the question "Why do those changes fix that particular issue?" or "Why are those changes really necessary as improvements?"
  • I made sure the commit message title starts with "fix #424242:" if there is a related issue
  • I created the test (mtest, vtest, script test) to verify the changes I made

@orivej orivej changed the title Fix building with -Werror=format-security [MU3] Fix building with -Werror=format-security Dec 19, 2020
@@ -2001,7 +2001,7 @@ MuseScore::MuseScore()
const bool loadSuccess = _loginManager->load();

if (cliSaveOnline && !loadSuccess) {
qFatal(qUtf8Printable(tr("No login credentials stored. Please sign in via the GUI.")));
qFatal("No login credentials stored. Please sign in via the GUI.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Veto. This way that text is not translatable

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No other qFatal is translatable. (I don't think that qFatal, qWarning, and other developer messages need translation.)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO they do, all of them.

Not the qDebug() ones though, not sure about qWarning().

If at that place the translations engine is available, which for example it is not at the place wherethe Usage message is printed

At this place translations are avaibable though, as far as I can tell.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about qFatal("%s", qUtf8Printable(tr("No login credentials stored. Please sign in via the GUI.")));

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@orivej, does this work:

QString msg = tr("No login credentials stored. Please sign in via the GUI.");
qFatal(qUtf8Printable(msg));

Or

auto msg = qUtf8Printable(tr("No login credentials stored. Please sign in via the GUI."));
qFatal(msg);

?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, makes sense (we really don't want a core dump here), so here we might better be using fprintf(stderr, "...") or std::cerr << "..." followed by exit(EXIT_FAILURE);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Jojo-Schmitz, what about qWarning() << "..." followed by exit(EXIT_FAILURE)?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would work too I guess. Not sure though whether either of these functions prefixes the (error) message with "Fatal:", "Warning:" or some such

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and whether and how it works on Windows commandline (but there I'm not sure about `cerr? and the likes either)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. I had to use ::exit because exit resolves into QCoreApplication::exit() (exit from the main loop), which does nothing when the main loop is not running.

Support translating messages.

Avoid qFatal since it generates a core dump and is used for
untranslated developer messages.

Use ::exit() because exit() refers to QCoreApplication::exit().

Fixes building with -Werror=format-security.
@orivej orivej changed the title [MU3] Fix building with -Werror=format-security [MU3] Fix printing user errors in musescore.cpp Dec 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants