Merge tag 'android-security-11.0.0_r50' into int/11/fp3
Android security 11.0.0 release 50
* tag 'android-security-11.0.0_r50':
An enum is initialized as zero if it doesn't have default value
Change-Id: If41c5d1ad47590dd9ebf4b4a10dd26606f34fc5d
diff --git a/generate_cpp.cpp b/generate_cpp.cpp
index cc25657..bbee9b3 100644
--- a/generate_cpp.cpp
+++ b/generate_cpp.cpp
@@ -1111,6 +1111,13 @@
if (variable->GetDefaultValue()) {
out << " = " << cppType.c_str() << "(" << variable->ValueString(ConstantValueDecorator)
<< ")";
+ } else if (auto type = typenames.TryGetDefinedType(variable->GetType().GetName()); type) {
+ if (auto enum_type = type->AsEnumDeclaration(); enum_type) {
+ if (!variable->GetType().IsArray()) {
+ // if an enum doesn't have explicit default value, do zero-initialization
+ out << " = " << cppType << "(0)";
+ }
+ }
}
out << ";\n";
diff --git a/generate_ndk.cpp b/generate_ndk.cpp
index 274d283..0efd7eb 100644
--- a/generate_ndk.cpp
+++ b/generate_ndk.cpp
@@ -879,6 +879,13 @@
out << NdkNameOf(types, variable->GetType(), StorageMode::STACK) << " " << variable->GetName();
if (variable->GetDefaultValue()) {
out << " = " << variable->ValueString(ConstantValueDecorator);
+ } else if (auto type = types.TryGetDefinedType(variable->GetType().GetName()); type) {
+ if (auto enum_type = type->AsEnumDeclaration(); enum_type) {
+ if (!variable->GetType().IsArray()) {
+ // if an enum doesn't have explicit default value, do zero-initialization
+ out << " = " << NdkNameOf(types, variable->GetType(), StorageMode::STACK) << "(0)";
+ }
+ }
}
out << ";\n";
}