Fix problem where unknown option is not an error.
If the first option is found, then any unknown options are simply
ignored, but do not produce an error. Fixed this so that each
option found is actually verified to exist.
Bug: 27620263
(cherry picked from commit a4b14252752d14454afb48feb3272e8689e3a66d)
Change-Id: I709774456283879e2a8aa5ce375899eaa79f6bc3
diff --git a/libc/malloc_debug/Config.cpp b/libc/malloc_debug/Config.cpp
index 4586fda3..ded618c 100644
--- a/libc/malloc_debug/Config.cpp
+++ b/libc/malloc_debug/Config.cpp
@@ -333,9 +333,9 @@
size_t value;
bool value_set;
PropertyParser parser(property_str);
- bool found = false;
bool valid = true;
while (valid && parser.Get(&property, &value, &value_set)) {
+ bool found = false;
for (size_t i = 0; i < sizeof(features)/sizeof(Feature); i++) {
if (property == features[i].name) {
if (features[i].option == 0 && features[i].combo_option) {
diff --git a/libc/malloc_debug/tests/malloc_debug_config_tests.cpp b/libc/malloc_debug/tests/malloc_debug_config_tests.cpp
index a6cea98..85d5cb5 100644
--- a/libc/malloc_debug/tests/malloc_debug_config_tests.cpp
+++ b/libc/malloc_debug/tests/malloc_debug_config_tests.cpp
@@ -124,6 +124,14 @@
ASSERT_STREQ((log_msg + usage_string).c_str(), getFakeLogPrint().c_str());
}
+TEST_F(MallocDebugConfigTest, good_option_and_bad_option) {
+ ASSERT_FALSE(InitConfig("backtrace unknown_option"));
+
+ ASSERT_STREQ("", getFakeLogBuf().c_str());
+ std::string log_msg("6 malloc_debug malloc_testing: unknown option unknown_option\n");
+ ASSERT_STREQ((log_msg + usage_string).c_str(), getFakeLogPrint().c_str());
+}
+
TEST_F(MallocDebugConfigTest, unparseable_number) {
ASSERT_FALSE(InitConfig("backtrace=XXX"));