Fix default enum values in help output
authorTeemu Murtola <teemu.murtola@gmail.com>
Sun, 16 Feb 2014 04:48:39 +0000 (06:48 +0200)
committerGerrit Code Review <gerrit@gerrit.gromacs.org>
Sun, 16 Feb 2014 09:30:47 +0000 (10:30 +0100)
nenum() does not return an enum value, but an index into the underlying
array, which means that the first element is 1 and not zero like the
code assumed.  The help output was off-by-one, and could error out if
some environment variable was set that was affecting the help output.

Fixes #1438.

Change-Id: Iec2f05c9ced55868902069ce59bc4979a6879f86

src/gromacs/commandline/pargs.cpp

index f1fa5ae42f1553af184e0f3053154a6e853ba31f..5fab063d6808db46d4dd03eed69a29213a09bf7d 100644 (file)
@@ -585,7 +585,7 @@ void pargsToOptions(Options *options, t_pargs *pa)
             return;
         case etENUM:
             options->addOption(
-                StringOption(name).defaultEnumIndex(nenum(pa->u.c))
+                StringOption(name).defaultEnumIndex(nenum(pa->u.c) - 1)
                     .enumValueFromNullTerminatedArray(pa->u.c + 1)
                     .description(desc).hidden(bHidden));
             return;