Options: Correctly check for missing arguments
authorPavel Labath <pavel@labath.sk>
Tue, 25 Jun 2019 14:02:39 +0000 (14:02 +0000)
committerPavel Labath <pavel@labath.sk>
Tue, 25 Jun 2019 14:02:39 +0000 (14:02 +0000)
commit34cac0955d7f77a402d2994d6c341fea08d369cf
tree033cb2f10edfc4e8275376a9984a0d0760eca3f6
parentf4e51dd2cd5bcc101533fa84700a0afb7ae911ff
Options: Correctly check for missing arguments

Relying on the value of optind for detecting missing arguments is
unreliable because its value after a failed parse is an implementation
detail. A more correct way to achieve this is to pass ':' at the
beginning of option string, which tells getopt to return ':' for missing
arguments.

For this to work, I also had to add a nullptr at the end of the argv
vector, as some getopt implementations did not work without that. This
is also an implementation detail, as getopt should normally be called
with argc+argc "as to main function" (i.e. null-terminated).

Thanks to Michał Górny for testing this patch out on NetBSD.

llvm-svn: 364317
lldb/source/Interpreter/Options.cpp