aidl: Options - avoid calling exit(3)
The fuzzer considers this a fatal error.
Bug: 195473218
Test: aidl_unittests + the following commands:
# in a directory without a file named
# 'alskdjflsakdjflkasjdflkajdslfkajsdf', this command fails:
aidl alskdjflsakdjflkasjdflkajdslfkajsdf
# this command returns a successful result, and nothing else is done
aidl --help
Change-Id: I9c0509dae8c4516d8ca57b7a203b51acb5848725
diff --git a/aidl.cpp b/aidl.cpp
index 38b8220..bb8f14e 100644
--- a/aidl.cpp
+++ b/aidl.cpp
@@ -775,6 +775,9 @@
int ret = 1;
switch (options.GetTask()) {
+ case Options::Task::HELP:
+ ret = 0;
+ break;
case Options::Task::COMPILE:
ret = android::aidl::compile_aidl(options, io_delegate);
break;
diff --git a/options.cpp b/options.cpp
index a4dafba..b79c4f1 100644
--- a/options.cpp
+++ b/options.cpp
@@ -26,6 +26,7 @@
#include <sstream>
#include <string>
+#include <android-base/logging.h>
#include <android-base/strings.h>
#include "aidl_language.h"
@@ -368,14 +369,17 @@
break;
case 'e':
std::cerr << GetUsage();
- exit(0);
+ task_ = Task::HELP;
+ CHECK(Ok());
+ return;
case 'i':
output_file_ = Trim(optarg);
task_ = Task::DUMP_MAPPINGS;
break;
default:
- std::cerr << GetUsage();
- exit(1);
+ error_message_ << GetUsage();
+ CHECK(!Ok());
+ return;
}
} // while
diff --git a/options.h b/options.h
index ebbd004..9f645a8 100644
--- a/options.h
+++ b/options.h
@@ -77,7 +77,7 @@
public:
enum class Language { UNSPECIFIED, JAVA, CPP, NDK, RUST };
- enum class Task { UNSPECIFIED, COMPILE, PREPROCESS, DUMP_API, CHECK_API, DUMP_MAPPINGS };
+ enum class Task { UNSPECIFIED, HELP, COMPILE, PREPROCESS, DUMP_API, CHECK_API, DUMP_MAPPINGS };
enum class CheckApiLevel { COMPATIBLE, EQUAL };