10
10
#include < fstream>
11
11
#include < iostream>
12
12
#include < string>
13
+ #include < utility>
13
14
#include < vector>
14
15
15
16
int main (int argc, char **argv)
@@ -30,49 +31,76 @@ int main(int argc, char **argv)
30
31
const char c = arg[1 ];
31
32
switch (c) {
32
33
case ' D' : { // define symbol
34
+ found = true ;
33
35
const char * const value = arg[2 ] ? (argv[i] + 2 ) : argv[++i];
36
+ if (!value) {
37
+ std::cout << " error: option -D with no value." << std::endl;
38
+ error = true ;
39
+ break ;
40
+ }
34
41
dui.defines .push_back (value);
35
- found = true ;
36
42
break ;
37
43
}
38
44
case ' U' : { // undefine symbol
45
+ found = true ;
39
46
const char * const value = arg[2 ] ? (argv[i] + 2 ) : argv[++i];
47
+ if (!value) {
48
+ std::cout << " error: option -U with no value." << std::endl;
49
+ error = true ;
50
+ break ;
51
+ }
40
52
dui.undefined .insert (value);
41
- found = true ;
42
53
break ;
43
54
}
44
55
case ' I' : { // include path
45
- const char * const value = arg[2 ] ? (argv[i] + 2 ) : argv[++i];
46
- dui.includePaths .push_back (value);
47
56
found = true ;
57
+ const char * const value = arg[2 ] ? (arg + 2 ) : argv[++i];
58
+ if (!value) {
59
+ std::cout << " error: option -I with no value." << std::endl;
60
+ error = true ;
61
+ break ;
62
+ }
63
+ dui.includePaths .push_back (value);
48
64
break ;
49
65
}
50
66
case ' i' :
51
67
if (std::strncmp (arg, " -include=" ,9 )==0 ) {
52
- dui.includes .push_back (arg+9 );
53
68
found = true ;
69
+ std::string value = arg + 9 ;
70
+ if (value.empty ()) {
71
+ std::cout << " error: option -include with no value." << std::endl;
72
+ error = true ;
73
+ break ;
74
+ }
75
+ dui.includes .push_back (std::move (value));
54
76
} else if (std::strncmp (arg, " -is" ,3 )==0 ) {
55
- use_istream = true ;
56
77
found = true ;
78
+ use_istream = true ;
57
79
}
58
80
break ;
59
81
case ' s' :
60
82
if (std::strncmp (arg, " -std=" ,5 )==0 ) {
61
- dui.std = arg + 5 ;
62
83
found = true ;
84
+ std::string value = arg + 5 ;
85
+ if (value.empty ()) {
86
+ std::cout << " error: option -std with no value." << std::endl;
87
+ error = true ;
88
+ break ;
89
+ }
90
+ dui.std = std::move (value);
63
91
}
64
92
break ;
65
93
case ' q' :
66
- quiet = true ;
67
94
found = true ;
95
+ quiet = true ;
68
96
break ;
69
97
case ' e' :
70
- error_only = true ;
71
98
found = true ;
99
+ error_only = true ;
72
100
break ;
73
101
case ' f' :
74
- fail_on_error = true ;
75
102
found = true ;
103
+ fail_on_error = true ;
76
104
break ;
77
105
}
78
106
if (!found) {
0 commit comments