Reset optarg in Coordinator::parseOptions
Coordinator::parseOptions assumes optarg will be null for options
without an argument, but that is not specified by POSIX. Reset
optarg to nullptr before calling getopt again to fix
CoordinatorCustomArgParseTest when building with USE_HOST_MUSL=true
Test: USE_HOST_MUSL=true atest --host hidl-gen-host_test
Change-Id: Ida17e68fcaf5c79d5a634501b46f8d1ff5cddc7f
diff --git a/Coordinator.cpp b/Coordinator.cpp
index 4cd9f26..4342d03 100644
--- a/Coordinator.cpp
+++ b/Coordinator.cpp
@@ -1042,6 +1042,10 @@
// something downstream should handle these cases
default: { handleArg(res, optarg); }
}
+ // glibc sets optarg to NULL for options without an argument, but POSIX doesn't
+ // require it musl libc does not. Reset it here so that the next call to
+ // handleArg doesn't pass a stale value.
+ optarg = nullptr;
}
if (getRootPath().empty()) {