summaryrefslogtreecommitdiff
path: root/Games/Minesweeper
diff options
context:
space:
mode:
authorJesse <Jooster669@gmail.com>2020-02-26 21:32:47 +1100
committerGitHub <noreply@github.com>2020-02-26 11:32:47 +0100
commitd8791025492fe0bed8840fd31f190643f5425713 (patch)
tree56c296485f44765a03b74ccca39f55285263eed4 /Games/Minesweeper
parent35024154cc6028ffa8a4a79e27fa555680569f8c (diff)
downloadserenity-d8791025492fe0bed8840fd31f190643f5425713.zip
Minesweeper: Perform sanity check on configuration (#1300)
This addresses the issue found in #1261. Previously we weren't doing any form of sanity checking on the values in the configuration file, meaning that a user could input a ridiculous number of mines such that the number of mines is larger than the number of squares on the field.
Diffstat (limited to 'Games/Minesweeper')
-rw-r--r--Games/Minesweeper/Field.cpp8
1 files changed, 7 insertions, 1 deletions
diff --git a/Games/Minesweeper/Field.cpp b/Games/Minesweeper/Field.cpp
index 36d7449672..13b86757c0 100644
--- a/Games/Minesweeper/Field.cpp
+++ b/Games/Minesweeper/Field.cpp
@@ -156,7 +156,13 @@ Field::Field(GUI::Label& flag_label, GUI::Label& time_label, GUI::Button& face_b
int mine_count = config->read_num_entry("Game", "MineCount", 10);
int rows = config->read_num_entry("Game", "Rows", 9);
int columns = config->read_num_entry("Game", "Columns", 9);
- set_field_size(rows, columns, mine_count);
+
+ // Do a quick sanity check to make sure the user hasn't tried anything crazy
+ if (mine_count > rows * columns || rows <= 0 || columns <= 0 || mine_count <= 0)
+ set_field_size(9, 9, 10);
+ else
+ set_field_size(rows, columns, mine_count);
+
set_single_chording(single_chording);
}
}