aboutsummaryrefslogtreecommitdiff
path: root/diagnostics.cpp
diff options
context:
space:
mode:
authorJooyung Han <jooyung@google.com>2020-12-31 11:50:21 +0900
committerJooyung Han <jooyung@google.com>2020-12-31 11:50:21 +0900
commitc9b0c805599f6801481d35a1bfd8ab5d9ffa0716 (patch)
tree08d00655086a1dea7fd7deb2e0e00c81c64d8ec6 /diagnostics.cpp
parent209c2866f40ce364724c4982241ced7fc8c0539d (diff)
downloadaidl-c9b0c805599f6801481d35a1bfd8ab5d9ffa0716.tar.gz
add -Wout-array
Methods having array output parameters, like void foo(out String[] ret) are usually bad because the output array size must be declared and allocated by the client in Java, and so the size of the array output cannot be chosen by the server. This undesirable behavior happens because of how arrays work in Java (they cannot be reallocated). Instead prefer APIs like String[] foo(). Bug: 168028537 Test: aidl_unittests Change-Id: Iccee9cf2cb9031f19b45972dadbaaa22670e09b4
Diffstat (limited to 'diagnostics.cpp')
-rw-r--r--diagnostics.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/diagnostics.cpp b/diagnostics.cpp
index 4af90331..9a4cfb8d 100644
--- a/diagnostics.cpp
+++ b/diagnostics.cpp
@@ -224,6 +224,20 @@ struct DiagnoseMixedOneway : DiagnosticsVisitor {
}
};
+struct DiagnoseOutArray : DiagnosticsVisitor {
+ DiagnoseOutArray(DiagnosticsContext& diag) : DiagnosticsVisitor(diag) {}
+ void Visit(const AidlMethod& m) override {
+ for (const auto& a : m.GetArguments()) {
+ if (a->GetType().IsArray() && a->IsOut()) {
+ diag.Report(m.GetLocation(), DiagnosticID::out_array)
+ << "The method '" << m.GetName() << "' an array output parameter '" << a->GetName()
+ << "'. Instead prefer APIs like '" << a->GetType().Signature() << " " << m.GetName()
+ << "(...).";
+ }
+ }
+ }
+};
+
bool Diagnose(const AidlDocument& doc, const DiagnosticMapping& mapping) {
DiagnosticsContext diag(mapping);
@@ -233,6 +247,7 @@ bool Diagnose(const AidlDocument& doc, const DiagnosticMapping& mapping) {
DiagnoseConstName{diag}.Check(doc);
DiagnoseExplicitDefault{diag}.Check(doc);
DiagnoseMixedOneway{diag}.Check(doc);
+ DiagnoseOutArray{diag}.Check(doc);
return diag.ErrorCount() == 0;
}