diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_flags.cc b/compiler-rt/lib/sanitizer_common/sanitizer_flags.cc index eca910c08090..2ef427844104 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_flags.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_flags.cc @@ -38,7 +38,8 @@ static bool GetFlagValue(const char *env, const char *name, pos += 1; end = internal_strchr(pos, '\''); } else { - end = internal_strchr(pos, ' '); + // Read until the next space or colon. + end = pos + internal_strcspn(pos, " :"); } if (end == 0) end = pos + internal_strlen(pos); diff --git a/compiler-rt/lib/sanitizer_common/tests/sanitizer_flags_test.cc b/compiler-rt/lib/sanitizer_common/tests/sanitizer_flags_test.cc index c0589f4d2e90..8c456c6a7e22 100644 --- a/compiler-rt/lib/sanitizer_common/tests/sanitizer_flags_test.cc +++ b/compiler-rt/lib/sanitizer_common/tests/sanitizer_flags_test.cc @@ -32,7 +32,7 @@ static void TestStrFlag(const char *start_value, const char *env, const char *final_value) { const char *flag = start_value; ParseFlag(env, &flag, kFlagName); - EXPECT_EQ(internal_strcmp(final_value, flag), 0); + EXPECT_EQ(0, internal_strcmp(final_value, flag)); } TEST(SanitizerCommon, BooleanFlags) { @@ -65,4 +65,21 @@ TEST(SanitizerCommon, StrFlags) { TestStrFlag("", "--flag_name=\"abc qwe\" asd", "abc qwe"); } +static void TestTwoFlags(const char *env, bool expected_flag1, + const char *expected_flag2) { + bool flag1 = !expected_flag1; + const char *flag2 = ""; + ParseFlag(env, &flag1, "flag1"); + ParseFlag(env, &flag2, "flag2"); + EXPECT_EQ(expected_flag1, flag1); + EXPECT_EQ(0, internal_strcmp(flag2, expected_flag2)); +} + +TEST(SanitizerCommon, MultipleFlags) { + TestTwoFlags("flag1=1 flag2='zzz'", true, "zzz"); + TestTwoFlags("flag2='qxx' flag1=0", false, "qxx"); + TestTwoFlags("flag1=false:flag2='zzz'", false, "zzz"); + TestTwoFlags("flag2=qxx:flag1=yes", true, "qxx"); +} + } // namespace __sanitizer