Remove ErrorMode_Ignore.
Before:
_hidl_err = ... writeInt ...
_hidl_err = ... writeLong ...
...
// end traces
...
_hidl_cb(...)
return _hidl_err
This has two problems:
- _hidl_cb should not be called if there is an error
- _hidl_err might be an error initially and then not an error later
(although this is theoretical. Since HIDL structures are fixed-length on
the parcel itself, I can't find any case where this be a problem).
After:
_hidl_err = ... writeInt ...
if (_hidl_err != OK) goto _hidl_error;
_hidl_err = ... writeLong ...
if (_hidl_err != OK) goto _hidl_error;
...
_hidl_error:
// end traces
...
if (_hidl_err != OK) return _hidl_err;
_hidl_cb(...)
return _hidl_err
Fixes: 129708508
Test: ./test/run_all_device_tests.sh
Change-Id: I833a6b979871ba53ccbdfdb7ae5eef8403ce0772
diff --git a/generateCpp.cpp b/generateCpp.cpp
index 510a96e..72c8e82 100644
--- a/generateCpp.cpp
+++ b/generateCpp.cpp
@@ -1515,7 +1515,11 @@
"_hidl_reply",
true, /* parcelObjIsPointer */
false, /* isReader */
- Type::ErrorMode_Ignore);
+ Type::ErrorMode_Goto);
+
+ out.unindent();
+ out << "_hidl_error:\n";
+ out.indent();
generateCppInstrumentationCall(
out,
@@ -1523,6 +1527,7 @@
method,
superInterface);
+ out << "if (_hidl_err != ::android::OK) { return _hidl_err; }\n";
out << "_hidl_cb(*_hidl_reply);\n";
} else {
if (returnsValue) {
@@ -1572,16 +1577,23 @@
true /* parcelObjIsPointer */,
arg,
false /* reader */,
- Type::ErrorMode_Ignore,
+ Type::ErrorMode_Goto,
true /* addPrefixToName */);
}
+ if (!method->results().empty()) {
+ out.unindent();
+ out << "_hidl_error:\n";
+ out.indent();
+ }
+
generateCppInstrumentationCall(
out,
InstrumentationEvent::SERVER_API_EXIT,
method,
superInterface);
+ out << "if (_hidl_err != ::android::OK) { return; }\n";
out << "_hidl_cb(*_hidl_reply);\n";
out.unindent();