]> granicus.if.org Git - libvpx/commitdiff
fix UB when initializing parameterized tests
authorMatthias Räncker <theonetruecamper@gmx.de>
Wed, 19 Sep 2018 07:47:27 +0000 (09:47 +0200)
committerMatthias Räncker <theonetruecamper@gmx.de>
Thu, 20 Sep 2018 09:51:26 +0000 (11:51 +0200)
When running tests built with
-fsanitize=undefined and--disable-optimizations
the sanitizer will emit errors of the following general form:

runtime error: member call on address 0xxxxxxxxx which does not
point to an object of type 'WithParamInterface'
0xxxxxxxxx: note: object has invalid vptr
 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  00 ...
              ^~~~~~~~~~~~~~~~~~~~~~~
              invalid vptr

This can be traced to calls to WithParamInterface<T>::GetParam before
the object argument has been initialized. Although GetParam only
accesses static data it is a non-static member function. This causes
that call to have undefined behaviour.
The patch makes GetParam a static member function.

upstream pull request:
https://github.com/google/googletest/pull/1830

The alternative - if the pull request is denied - would be to
modify all parameterized tests to have them derive from
::libvpx_test::CodecTestWith*Params as the first base class.

Signed-off-by: Matthias Räncker <theonetruecamper@gmx.de>
Change-Id: I8e91a4fba5438c9b3e93fa398f789115ab86b521

third_party/googletest/README.libvpx
third_party/googletest/src/include/gtest/gtest.h

index da6f77804152fd724c4426d38927f16dc531236e..f4ca22bbadbffec5123f5b8af132fbcd8e12592a 100644 (file)
@@ -20,3 +20,7 @@ Local Modifications:
    LICENSE
    README.md
    src
+
+- Make WithParamInterface<T>::GetParam static in order to avoid
+  initialization issues
+  https://github.com/google/googletest/pull/1830
index 26e787d99eb21c508d776231d1bc3b5b19638f2e..456e4a84961b60745d77c33ac4b186130e93cddf 100644 (file)
@@ -1775,11 +1775,8 @@ class WithParamInterface {
   virtual ~WithParamInterface() {}
 
   // The current parameter value. Is also available in the test fixture's
-  // constructor. This member function is non-static, even though it only
-  // references static data, to reduce the opportunity for incorrect uses
-  // like writing 'WithParamInterface<bool>::GetParam()' for a test that
-  // uses a fixture whose parameter type is int.
-  const ParamType& GetParam() const {
+  // constructor.
+  static const ParamType& GetParam() {
     GTEST_CHECK_(parameter_ != NULL)
         << "GetParam() can only be called inside a value-parameterized test "
         << "-- did you intend to write TEST_P instead of TEST_F?";