Skip to content

Commit 2b8ae77

Browse files
author
daltomi
committed
Fixed parse command-line options
- Fix Segmentation fault - Allow to use single character option.
1 parent 0039b29 commit 2b8ae77

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/cbm.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,13 @@ extern int optind, opterr, optopt;
4848
namespace {
4949

5050
// Globals
51+
static const char* optstring = "hV";
52+
5153
struct option longopts[] =
5254
{
53-
{ "help", no_argument, NULL, 'h' },
54-
{ "version", no_argument, NULL, 'V' }
55+
{ "help", no_argument, NULL, 'h' },
56+
{ "version", no_argument, NULL, 'V' },
57+
{ NULL, 0, NULL, 0 }
5558
};
5659

5760
volatile bool quit = false;
@@ -117,7 +120,7 @@ int main(int argc, char **argv) {
117120
opterr = 0;
118121
bool getopt_done = false;
119122
while (!getopt_done) {
120-
int ch = getopt_long(argc, argv, "", longopts, NULL);
123+
int ch = getopt_long(argc, argv, optstring, longopts, NULL);
121124
switch (ch) {
122125
case 'h':
123126
usage(std::cout);

0 commit comments

Comments
 (0)