OSDN Git Service

Fix problem where unknown option is not an error.
authorChristopher Ferris <cferris@google.com>
Mon, 14 Mar 2016 22:29:46 +0000 (15:29 -0700)
committerChristopher Ferris <cferris@google.com>
Tue, 15 Mar 2016 18:18:15 +0000 (11:18 -0700)
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

libc/malloc_debug/Config.cpp
libc/malloc_debug/tests/malloc_debug_config_tests.cpp

index 4586fda..ded618c 100644 (file)
@@ -333,9 +333,9 @@ bool Config::SetFromProperties() {
   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) {
index a6cea98..85d5cb5 100644 (file)
@@ -124,6 +124,14 @@ TEST_F(MallocDebugConfigTest, unknown_option) {
   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"));