From 2d143a9147d418ed5dfcce73ea9c27af2680d140 Mon Sep 17 00:00:00 2001
From: zeromus <zeromus@users.sf.net>
Date: Tue, 26 Jul 2016 17:15:27 +0000
Subject: [PATCH] fix infinite loop bugs in commandline parsing

---
 desmume/src/commandline.cpp | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/desmume/src/commandline.cpp b/desmume/src/commandline.cpp
index 15959e45a..476076335 100644
--- a/desmume/src/commandline.cpp
+++ b/desmume/src/commandline.cpp
@@ -254,7 +254,8 @@ bool CommandLine::parse(int argc,char **argv)
 		};
 
 		int c = getopt_long(argc,argv,"",long_options,&option_index);
-		if(c == -1)
+		if(c == -1) break;
+		if(c == '?') 
 			break;
 
 		switch(c)
@@ -361,8 +362,7 @@ bool CommandLine::parse(int argc,char **argv)
 	int remain = argc-optind;
 	if(remain==1)
 		nds_file = argv[optind];
-	else if(remain>1)
-		return false;
+	else if(remain>1) return false;
 	
 	return true;
 }
@@ -443,9 +443,7 @@ bool CommandLine::validate()
 
 void CommandLine::errorHelp(const char* binName)
 {
-	//TODO - strip this down to just the filename
-	printerror("USAGE: %s [options] [nds-file]\n", binName);
-	printerror("USAGE: %s --help    - for help\n", binName);
+	printerror(help_string);
 }
 
 void CommandLine::process_movieCommands()