Fix segfault when attempting to generate or enter in an invalid game variant.
ClosedPublic

Authored by ouwerkerk on Apr 30 2017, 4:54 PM.

Details

Summary

This change resolves T5981.
The segfault is fixed by checking whether or not a Game object is valid, before letting the user play with it.

Test Plan

Manually added a borked game variant in KSudoku::updateShapesList() using a CustomGameVariant with null QUrl.
Compiled and verified the segfault no longer occurred.

/*
 * For the purpose of testing the change, a deliberately borked game variant.
 * TODO: remove in final version of diff.
 */
variant = new CustomGame(i18n("Invalid TODO Remove me"), QUrl(), m_gameVariants);
variant->setDescription(i18n("Invalid TODO Remove me"));
variant->setIcon("ksudoku-ksudoku_9x9");

Diff Detail

Repository
R417 KSudoku
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
ouwerkerk created this revision.Apr 30 2017, 4:54 PM
Restricted Application added a reviewer: KDE Games. · View Herald TranscriptApr 30 2017, 4:54 PM
Restricted Application added a subscriber: KDE Games. · View Herald Transcript
ltoscano accepted this revision.Apr 30 2017, 10:17 PM
ltoscano added a subscriber: ltoscano.

The real test could be probably a unit test :)
It is true that many others are missing too (there are 0 tests now). If you feel about trying writing one, you are welcome.

In the meantime, the change looks definitely correct.

This revision is now accepted and ready to land.Apr 30 2017, 10:17 PM
ouwerkerk updated this revision to Diff 14044.May 1 2017, 6:10 AM

Provide feedback to the user when unable to start a puzzle of a particular (invalid) game variant.

The real test could be probably a unit test :)

Unfortunately that may not be so easy: the code is part of private slots (which are in turn wired up to buttons that look like they come from a privately inherited base class).
Is it even possible to invoke private slots through the Qt meta object system directly?

ouwerkerk updated this revision to Diff 14058.May 1 2017, 5:59 PM

Use KMessageBox::sorry() instead of KMessageBox::information() type message boxes.

This revision was automatically updated to reflect the committed changes.

(it was re-approved on IRC)