From 57f7772b76603b2a91c0a9513acbfde0a5098a93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matt=C3=A9o=20Delabre?= Date: Sat, 2 Apr 2016 15:06:38 +0200 Subject: [PATCH] =?UTF-8?q?V=C3=A9rification=20de=20l'existence=20du=20typ?= =?UTF-8?q?e=20d'objet=20avant=20son=20d=C3=A9codage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/game.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/game.cpp b/src/game.cpp index 4460943..2333a32 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -90,6 +90,15 @@ void Game::load(std::ifstream& file) { for (int i = 0; i < block_count; i++) { char block_type; file.read(&block_type, 1); + + // vérifie que le type est pris en charge + // pour éviter une erreur de segmentation + if (object_type_map.count(block_type) == 0) { + throw std::runtime_error( + "Impossible de lire le fichier : type d'objet inconnu" + ); + } + objects.push_back(object_type_map[block_type](file)); } }