From c3507ebf21a86c84194beb6200bd865205b674fe Mon Sep 17 00:00:00 2001 From: Andrei Pavel Date: Fri, 15 Dec 2023 12:36:24 +0200 Subject: [#2788] reset optarg optarg is not reset in musl's getopt and it leaks values to other flags. Reset it for all systems because it cannot hurt. If you remove the optarg reset, you should see the bug in action on alpine systems in DstubControllerTest.commandLineArgs when parsing argv2: ``` [ RUN ] DStubControllerTest.commandLineArgs d_controller_unittests.cc:102: Failure Expected equality of these values: std::string(ex.what()) Which is: "unsupported option: -b cfgName" "unsupported option: -b" [ FAILED ] DStubControllerTest.commandLineArgs (14 ms) ``` --- src/lib/process/d_controller.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'src/lib') diff --git a/src/lib/process/d_controller.cc b/src/lib/process/d_controller.cc index e8d72d5f2e..f08794a9c3 100644 --- a/src/lib/process/d_controller.cc +++ b/src/lib/process/d_controller.cc @@ -250,6 +250,7 @@ DControllerBase::parseArgs(int argc, char* argv[]) { // ("c" or "d") handle it here. If its a valid custom option, then // invoke customOption. int ch; + optarg = 0; opterr = 0; optind = 1; std::string opts("dvVWc:t:" + getCustomOpts()); -- cgit v1.2.3