Package: marsshooter / 0.7.5-2

fix-segfault-when-using-arguments-without-path.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
From: Sylvain Boilard <boilard@crans.org>
Date: Mon, 3 Feb 2014 18:25:06 +0100
Subject: fix segfault when using arguments without path

Forwarded: https://github.com/thelaui/M.A.R.S./pull/6
---
 src/main.cpp | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/main.cpp b/src/main.cpp
index 8346411..3fa97a0 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -61,10 +61,16 @@ int main(int argc, char* argv[]) {
             return 0;
         }
         else if (std::string(argv[i]) == "-cfg") {
-            settings::C_configPath = argv[++i];
+            if (++i < argc)
+                settings::C_configPath = argv[i];
+            else
+                std::cout << "Option \"-cfg\" expects a path to be provided following it.\n";
         }
         else if (std::string(argv[i]) == "-data") {
-            settings::C_dataPath = argv[++i];
+            if (++i < argc)
+                settings::C_dataPath = argv[i];
+            else
+                std::cout << "Option \"-data\" expects a path to be provided following it.\n";
         }
         else {
             std::cout << "Unknown option \"" << argv[i] << "\". Use -help for a complete list of supported flags.\n";