Skip to content

Commit 89d5223

Browse files
Charmrun: Fix some parameter error messages
Before: $ ./charmrun +p ERROR> syntax: (null) must be followed by a value. $ ./charmrun +p x ERROR> syntax: Illegal value for x After: $ ./charmrun +p ERROR> syntax: +p must be followed by a value. $ ./charmrun +p x ERROR> syntax: Illegal value for +p
1 parent 23c9f5c commit 89d5223

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/util/charmrun-src/charmrun.C

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -594,14 +594,14 @@ static int pparam_parseopt()
594594
sprintf(pparam_error, "Option %s not recognized.", opt);
595595
return -1;
596596
} else {
597-
/*Unrecognized + option-- skip it.*/
597+
/*Unrecognized single '+' option-- skip it.*/
598598
pparam_pos++;
599599
return 0;
600600
}
601601
}
602602
auto def = deffind.def;
603603
/* handle flag-options */
604-
if ((def->type == 'f') && (opt[1] != '+') && (opt[2])) {
604+
if ((def->type == 'f') && (opt[1] != '+') && (opt[2] != '\0')) {
605605
sprintf(pparam_error, "Option %s should not include a value", opt);
606606
return -1;
607607
}
@@ -611,19 +611,20 @@ static int pparam_parseopt()
611611
return 0;
612612
}
613613
/* handle non-flag options */
614-
if ((opt[1] == '+') || (opt[2] == 0)) {
614+
const char * optname = opt;
615+
if ((opt[1] == '+') || (opt[2] == '\0')) { // special single '+' handling
615616
pparam_delarg(pparam_pos);
616617
opt = pparam_argv[pparam_pos];
617618
} else
618619
opt += 2;
619-
if ((opt == 0) || (opt[0] == 0)) {
620-
sprintf(pparam_error, "%s must be followed by a value.", opt);
620+
if ((opt == nullptr) || (opt[0] == '\0')) {
621+
sprintf(pparam_error, "%s must be followed by a value.", optname);
621622
return -1;
622623
}
623624
int ok = pparam_setdef(def, opt);
624625
pparam_delarg(pparam_pos);
625626
if (ok < 0) {
626-
sprintf(pparam_error, "Illegal value for %s", opt);
627+
sprintf(pparam_error, "Illegal value for %s", optname);
627628
return -1;
628629
}
629630
return 0;

0 commit comments

Comments
 (0)