Skip to content

Commit b474d59

Browse files
committed
Ensure the configs flag has a value
The config flag vector may increase in size after the default values have been set. This change makes sure the newly added elements have a valid value. Bug: b/441907863
1 parent 5f68d03 commit b474d59

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

base/cvd/cuttlefish/host/libs/config/config_flag.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ namespace cuttlefish {
5858

5959
namespace {
6060

61+
constexpr auto kDefaultConfig = "phone";
62+
6163
std::string VectorizedFlagValue(const std::vector<std::string>& value) {
6264
return absl::StrJoin(value, ",");
6365
}
@@ -108,7 +110,7 @@ class ConfigFlagImpl : public ConfigFlag {
108110
INJECT(ConfigFlagImpl(ConfigReader& cr, SystemImageDirFlag& s))
109111
: config_reader_(cr),
110112
system_image_dir_flag_(s),
111-
configs_(s.Size(), "phone"),
113+
configs_(s.Size(), kDefaultConfig),
112114
is_default_(true) {
113115
auto help =
114116
"Config preset name. Will automatically set flag fields using the "
@@ -133,12 +135,11 @@ class ConfigFlagImpl : public ConfigFlag {
133135
CF_EXPECT(flag_.Parse(args), "Failed to parse `--config` flag");
134136

135137
if (is_default_) {
138+
configs_.resize(system_image_dir_flag_.Size());
136139
// The default value is read from android_info.txt when available
137140
for (size_t i = 0; i < configs_.size(); ++i) {
138141
std::optional<std::string> info_cfg = FindAndroidInfoConfig(i);
139-
if (info_cfg) {
140-
configs_[i] = *info_cfg;
141-
}
142+
configs_[i] = info_cfg.value_or(kDefaultConfig);
142143
}
143144
}
144145
std::map<std::string, std::vector<std::string>> flags;

0 commit comments

Comments
 (0)