Remove webrtc::test::InitFieldTrialsFromString(const std::string&).
This is done to solve a problem where a string literal is implicitly cast
to a temporary std::string when calling webrtc::test::InitFieldTrialsFromString
which passes a pointer to the internal representation to
webrtc::field_trial::InitFieldTrialFromString(char*). This pointer is
stored for later use, but the temporary std::string is destroyed as soon
as the function returns.
Using webrtc::field_trial::InitFieldTrialFromString(char*) instead,
avoids the implicit casts (but the caller still needs to ensure that
the char* outlives the program). The validation previously done by
webrtc::test::InitFieldTrialsFromString can now be done by manually
calling webrtc::test::ValidateFieldTrialsStringOrDie(const std::string&).
Add system_wrappers:field_trial_default as a direct dependency to
various targets to allow including the field_trials_default.h header.
Bug: webrtc:8812
Change-Id: Ib5a641ea255b1c16a8f7f35e1fe67f6c38a61da6
Reviewed-on: https://webrtc-review.googlesource.com/46141
Reviewed-by: Tommi <tommi@webrtc.org>
Commit-Queue: Oleh Prypin <oprypin@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#21856}
diff --git a/rtc_base/BUILD.gn b/rtc_base/BUILD.gn
index f18c0f5..f0e2fd7 100644
--- a/rtc_base/BUILD.gn
+++ b/rtc_base/BUILD.gn
@@ -896,6 +896,7 @@
":rtc_base",
":rtc_base_approved",
":rtc_base_tests_utils",
+ "../system_wrappers:field_trial_default",
"../test:field_trial",
"../test:test_support",
]
diff --git a/rtc_base/unittest_main.cc b/rtc_base/unittest_main.cc
index 330bd3f..aa8a11b 100644
--- a/rtc_base/unittest_main.cc
+++ b/rtc_base/unittest_main.cc
@@ -19,6 +19,7 @@
#include "rtc_base/logging.h"
#include "rtc_base/ssladapter.h"
#include "rtc_base/sslstreamadapter.h"
+#include "system_wrappers/include/field_trial_default.h"
#include "test/field_trial.h"
#include "test/testsupport/fileutils.h"
@@ -76,7 +77,10 @@
}
webrtc::test::SetExecutablePath(argv[0]);
- webrtc::test::InitFieldTrialsFromString(FLAG_force_fieldtrials);
+ webrtc::test::ValidateFieldTrialsStringOrDie(FLAG_force_fieldtrials);
+ // InitFieldTrialsFromString stores the char*, so the char array must outlive
+ // the application.
+ webrtc::field_trial::InitFieldTrialsFromString(FLAG_force_fieldtrials);
#if defined(WEBRTC_WIN)
if (!FLAG_default_error_handlers) {