From f3821d76d95576ff1be0dc3de4b74cdf70049a8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=BCnther?= Date: Wed, 31 Mar 2010 02:43:17 +0200 Subject: Fixed null pointer handling in History::add --- HISTORY | 1 + history.cpp | 15 +++++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/HISTORY b/HISTORY index a4397ba..56c2d35 100644 --- a/HISTORY +++ b/HISTORY @@ -97,3 +97,4 @@ ____-__-__: Version 0.3.5 - Converted documentation and source files to UTF-8. - Added unit tests. - Fixed segfault in History::current. +- Fixed null pointer handling in History::add. diff --git a/history.cpp b/history.cpp index d89d0d5..65e3a5f 100644 --- a/history.cpp +++ b/history.cpp @@ -61,14 +61,17 @@ Move* History::current() /** Add a new move */ void History::add(Move* move) { - for (unsigned int pos = history.size(); pos > executed; --pos) + if (move) { - // Remove object created outside of History - delete history.back(); - history.pop_back(); + for (unsigned int pos = history.size(); pos > executed; --pos) + { + // Remove object created outside of History + delete history.back(); + history.pop_back(); + } + history.push_back(move); + ++executed; } - history.push_back(move); - ++executed; } /** Set previous move as current */ -- cgit v1.2.3