Fix crash in Website::getGames
authorSude <lgogdownloader@gmail.com>
Thu, 19 Jan 2017 22:15:50 +0000 (00:15 +0200)
committerStephen Kitt <skitt@debian.org>
Wed, 5 Apr 2017 17:27:13 +0000 (18:27 +0100)
JSON value for updates can be null in some cases. For example when user owns a dlc but not the base game.
This caused a crash due to std::stoi throwing std::invalid_argument exception

Origin: upstream, 3.2, commit:22f47de4fcd8cd7ecc2a89fbb25f94efb1b3f743

Gbp-Pq: Name Fix-crash-in-Website-getGames.patch

src/website.cpp

index 08034324ab0e1f97063fabf7034873b2f1e5185e..8ca4c8ce2fa9992dc399dcc0611bc8ce2777bffe 100644 (file)
@@ -163,7 +163,31 @@ std::vector<gameItem> Website::getGames()
                 gameItem game;
                 game.name = product["slug"].asString();
                 game.id = product["id"].isInt() ? std::to_string(product["id"].asInt()) : product["id"].asString();
-                game.updates = product["updates"].isInt() ? product["updates"].asInt() : std::stoi(product["updates"].asString());
+
+                if (product.isMember("updates"))
+                {
+                    if (product["updates"].isNull())
+                    {
+                        /* In some cases the value can be null.
+                         * For example when user owns a dlc but not the base game
+                         * https://github.com/Sude-/lgogdownloader/issues/101
+                         * Assume that there are no updates in this case */
+                        game.updates = 0;
+                    }
+                    else if (product["updates"].isInt())
+                        game.updates = product["updates"].asInt();
+                    else
+                    {
+                        try
+                        {
+                            game.updates = std::stoi(product["updates"].asString());
+                        }
+                        catch (std::invalid_argument& e)
+                        {
+                            game.updates = 0; // Assume no updates
+                        }
+                    }
+                }
 
                 unsigned int platform = 0;
                 if (product["worksOn"]["Windows"].asBool())