[gnome-chess] Fix crash on invalid clock type in pgn
- From: Sahil Sareen <ssareen src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-chess] Fix crash on invalid clock type in pgn
- Date: Tue, 24 Mar 2015 15:11:28 +0000 (UTC)
commit e9d862cda33920c54254e32727319715531efcd9
Author: Sahil Sareen <sahil sareen hotmail com>
Date: Sat Mar 14 21:04:16 2015 +0530
Fix crash on invalid clock type in pgn
Use a simple clock for invalid clock types in pgn.
lib/chess-clock.vala | 5 +++--
lib/chess-pgn.vala | 16 +++++++++++++++-
2 files changed, 18 insertions(+), 3 deletions(-)
---
diff --git a/lib/chess-clock.vala b/lib/chess-clock.vala
index 0bb3854..df38fe6 100644
--- a/lib/chess-clock.vala
+++ b/lib/chess-clock.vala
@@ -14,7 +14,8 @@ public enum ClockType
{
SIMPLE,
FISCHER,
- BRONSTEIN;
+ BRONSTEIN,
+ INVALID;
public string to_string ()
{
@@ -42,7 +43,7 @@ public enum ClockType
case "bronstein":
return BRONSTEIN;
default:
- assert_not_reached ();
+ return INVALID;
}
}
}
diff --git a/lib/chess-pgn.vala b/lib/chess-pgn.vala
index 51e364f..cfe1fb4 100644
--- a/lib/chess-pgn.vala
+++ b/lib/chess-pgn.vala
@@ -235,6 +235,20 @@ enum State
public class PGN : Object
{
public List<PGNGame> games;
+ private void insert_tag (PGNGame game, string tag_name, string tag_value)
+ {
+ switch (tag_name)
+ {
+ case "X-GNOME-ClockType":
+ if (ClockType.string_to_enum (tag_value) == ClockType.INVALID)
+ {
+ warning ("Invalid clock type in PGN: %s, using a simple clock.", tag_value);
+ tag_value = "simple";
+ }
+ break;
+ }
+ game.tags.insert (tag_name, tag_value);
+ }
public PGN.from_string (string data) throws PGNError
{
@@ -389,7 +403,7 @@ public class PGN : Object
continue;
else if (c == ']')
{
- game.tags.insert (tag_name, tag_value.str);
+ insert_tag (game, tag_name, tag_value.str);
state = State.TAGS;
}
else
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]