Fossil SCM

fix option/argument parsing for the case where an option is missing a required argument.

bharder 2009-02-09 18:09 trunk
Commit f80303ac73628dbfe30abd5964792ae99e638dca
1 file changed +2 -1
+2 -1
--- src/main.c
+++ src/main.c
@@ -331,10 +331,11 @@
331331
int nLong;
332332
const char *zReturn = 0;
333333
assert( hasArg==0 || hasArg==1 );
334334
nLong = strlen(zLong);
335335
for(i=2; i<g.argc; i++){
336
+ if (i+hasArg >= g.argc) break;
336337
char *z = g.argv[i];
337338
if( z[0]!='-' ) continue;
338339
z++;
339340
if( z[0]=='-' ){
340341
if( z[1]==0 ){
@@ -369,11 +370,11 @@
369370
*/
370371
void verify_all_options(void){
371372
int i;
372373
for(i=1; i<g.argc; i++){
373374
if( g.argv[i][0]=='-' ){
374
- fossil_fatal("unrecognized command-line option: %s", g.argv[i]);
375
+ fossil_fatal("unrecognized command-line option, or missing argument: %s", g.argv[i]);
375376
}
376377
}
377378
}
378379
379380
/*
380381
--- src/main.c
+++ src/main.c
@@ -331,10 +331,11 @@
331 int nLong;
332 const char *zReturn = 0;
333 assert( hasArg==0 || hasArg==1 );
334 nLong = strlen(zLong);
335 for(i=2; i<g.argc; i++){
 
336 char *z = g.argv[i];
337 if( z[0]!='-' ) continue;
338 z++;
339 if( z[0]=='-' ){
340 if( z[1]==0 ){
@@ -369,11 +370,11 @@
369 */
370 void verify_all_options(void){
371 int i;
372 for(i=1; i<g.argc; i++){
373 if( g.argv[i][0]=='-' ){
374 fossil_fatal("unrecognized command-line option: %s", g.argv[i]);
375 }
376 }
377 }
378
379 /*
380
--- src/main.c
+++ src/main.c
@@ -331,10 +331,11 @@
331 int nLong;
332 const char *zReturn = 0;
333 assert( hasArg==0 || hasArg==1 );
334 nLong = strlen(zLong);
335 for(i=2; i<g.argc; i++){
336 if (i+hasArg >= g.argc) break;
337 char *z = g.argv[i];
338 if( z[0]!='-' ) continue;
339 z++;
340 if( z[0]=='-' ){
341 if( z[1]==0 ){
@@ -369,11 +370,11 @@
370 */
371 void verify_all_options(void){
372 int i;
373 for(i=1; i<g.argc; i++){
374 if( g.argv[i][0]=='-' ){
375 fossil_fatal("unrecognized command-line option, or missing argument: %s", g.argv[i]);
376 }
377 }
378 }
379
380 /*
381

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button