diff options
author | Cody Heiner <codyheiner@google.com> | 2024-02-15 00:28:08 +0000 |
---|---|---|
committer | Cody Heiner <codyheiner@google.com> | 2024-02-15 17:59:57 -0800 |
commit | d737c3ed06f9aef6d68456288a5250c3893a8ca5 (patch) | |
tree | 3e38e7d37b12019bbcafdc674a550f829945e8d3 /generate_cpp.cpp | |
parent | 03d191d6c98f6adf2382a2741b068b0260036679 (diff) | |
download | aidl-d737c3ed06f9aef6d68456288a5250c3893a8ca5.tar.gz |
Fix implicit narrowing conversion in generated C++ code
Also updates `auto` types to explicit types in order to improve readability and make it clear how and why different integral types are being used.
Note: the only manual change here is the change to `generate_cpp.cpp`.
The rest of the changes were produced by running:
`system/tools/aidl/tests/golden_test.sh update`
Test: build succeeds when generating code within a library that
uses -Wall -Werror flags (where it failed before this change).
Test: device runs normally.
Change-Id: I704e3322318d2fe327320b50519de1acbefc33f9
Diffstat (limited to 'generate_cpp.cpp')
-rw-r--r-- | generate_cpp.cpp | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/generate_cpp.cpp b/generate_cpp.cpp index 82907b5c..f8aed492 100644 --- a/generate_cpp.cpp +++ b/generate_cpp.cpp @@ -1153,7 +1153,7 @@ void GenerateReadFromParcel(CodeWriter& out, const AidlStructuredParcelable& par void GenerateWriteToParcel(CodeWriter& out, const AidlStructuredParcelable& parcel, const AidlTypenames& typenames) { out << "::android::status_t _aidl_ret_status = ::android::OK;\n"; - out << "auto _aidl_start_pos = " << kParcelVarName << "->dataPosition();\n"; + out << "size_t _aidl_start_pos = " << kParcelVarName << "->dataPosition();\n"; out << kParcelVarName << "->writeInt32(0);\n"; for (const auto& variable : parcel.GetFields()) { string method = ParcelWriteMethodOf(variable->GetType(), typenames); @@ -1171,9 +1171,9 @@ void GenerateWriteToParcel(CodeWriter& out, const AidlStructuredParcelable& parc out << "}\n"; } } - out << "auto _aidl_end_pos = " << kParcelVarName << "->dataPosition();\n"; + out << "size_t _aidl_end_pos = " << kParcelVarName << "->dataPosition();\n"; out << kParcelVarName << "->setDataPosition(_aidl_start_pos);\n"; - out << kParcelVarName << "->writeInt32(_aidl_end_pos - _aidl_start_pos);\n"; + out << kParcelVarName << "->writeInt32(static_cast<int32_t>(_aidl_end_pos - _aidl_start_pos));\n"; out << kParcelVarName << "->setDataPosition(_aidl_end_pos);\n"; out << "return _aidl_ret_status;\n"; } |