Skip to content

Commit 72813d1

Browse files
authored
Config::mapGetBool causes segmentation fault when value_out is nullptr (#1471)
Signed-off-by: Alejandro Hernandez Cordero <[email protected]>
1 parent 56ab4c9 commit 72813d1

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

rviz_common/src/rviz_common/config.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,10 @@ bool Config::mapGetFloat(const QString & key, float * value_out) const
264264

265265
bool Config::mapGetBool(const QString & key, bool * value_out) const
266266
{
267+
if (value_out == nullptr) {
268+
return false;
269+
}
270+
267271
QVariant v;
268272
if (mapGetValue(key, &v) && (v.type() == QVariant::Bool || v.type() == QVariant::String)) {
269273
*value_out = v.toBool();

rviz_common/test/config_test.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,17 @@ TEST(Config, mapGetValue_key_not_found_null_check) {
8181
EXPECT_EQ(s_default, "my_default_value");
8282
}
8383

84+
TEST(Config, handle_mixed_type_values_for_keys) {
85+
rviz_common::Config c;
86+
c.mapSetValue("mixed_key", "123abc");
87+
EXPECT_FALSE(c.mapGetInt("mixed_key", nullptr));
88+
EXPECT_FALSE(c.mapGetBool("mixed_key", nullptr));
89+
EXPECT_FALSE(c.mapGetFloat("mixed_key", nullptr));
90+
QString string_value;
91+
EXPECT_TRUE(c.mapGetString("mixed_key", &string_value));
92+
EXPECT_EQ(string_value, "123abc");
93+
}
94+
8495
int main(int argc, char ** argv)
8596
{
8697
testing::InitGoogleTest(&argc, argv);

0 commit comments

Comments
 (0)