Fixed ActionResultHolder for GCC 6 80/143480/2 accepted/tizen_4.0_unified accepted/tizen_5.0_unified accepted/tizen_5.5_unified accepted/tizen_5.5_unified_mobile_hotfix accepted/tizen_5.5_unified_wearable_hotfix accepted/tizen_6.0_unified accepted/tizen_6.0_unified_hotfix tizen_4.0 tizen_4.0_tv tizen_5.0 tizen_5.5 tizen_5.5_mobile_hotfix tizen_5.5_tv tizen_5.5_wearable_hotfix tizen_6.0 tizen_6.0_hotfix accepted/tizen/4.0/unified/20170828.222348 accepted/tizen/5.0/unified/20181102.024700 accepted/tizen/5.5/unified/20191031.005405 accepted/tizen/5.5/unified/mobile/hotfix/20201027.062307 accepted/tizen/5.5/unified/wearable/hotfix/20201027.102530 accepted/tizen/6.0/unified/20201030.104615 accepted/tizen/6.0/unified/hotfix/20201102.235742 accepted/tizen/unified/20170811.021225 submit/tizen/20170810.132456 submit/tizen/20210513.080406 submit/tizen_4.0/20170828.100005 submit/tizen_5.0/20181101.000006 submit/tizen_5.5/20191031.000006 submit/tizen_5.5_mobile_hotfix/20201026.185106 submit/tizen_5.5_wearable_hotfix/20201026.184306 submit/tizen_6.0/20201029.205501 submit/tizen_6.0_hotfix/20201102.192901 submit/tizen_6.0_hotfix/20201103.115101 tizen_4.0.IoT.p1_release tizen_4.0.IoT.p2_release tizen_4.0.m2_release tizen_5.5.m2_release tizen_6.0.m2_release
authorPawel Kowalski <p.kowalski2@partner.samsung.com>
Thu, 10 Aug 2017 05:58:20 +0000 (07:58 +0200)
committerPawel Kowalski <p.kowalski2@partner.samsung.com>
Thu, 10 Aug 2017 12:45:13 +0000 (14:45 +0200)
Compiling with GCC 6 lead to segfaults in unit tests written using
the gmock and gtest, because it invoked undefined behavior.

When optimizing, GCC assumes the 'this' pointer can never be null.
In the ActionResultHolder template, methods returned
null pointers and it caused segfaults. These null pointers were
replaced with pointers to dynamically created pointers to the
ActionResultHolder objects.

Source of patch:
https://github.com/google/googletest/issues/705
https://github.com/google/googletest/issues/705#issuecomment-235067917

Change-Id: Id617519921a0b6bdc3df01e417d762028ec132c7

include/gmock/gmock-spec-builders.h

index 312fbe8..2dd733b 100644 (file)
@@ -1370,6 +1370,8 @@ class ActionResultHolder : public UntypedActionResultHolderBase {
 template <>
 class ActionResultHolder<void> : public UntypedActionResultHolderBase {
  public:
+  explicit ActionResultHolder() {}
+
   void GetValueAndDelete() const { delete this; }
 
   virtual void PrintAsActionResult(::std::ostream* /* os */) const {}
@@ -1381,7 +1383,7 @@ class ActionResultHolder<void> : public UntypedActionResultHolderBase {
       const typename Function<F>::ArgumentTuple& args,
       const string& call_description) {
     func_mocker->PerformDefaultAction(args, call_description);
-    return NULL;
+    return new ActionResultHolder();
   }
 
   // Performs the given action and returns NULL.
@@ -1390,7 +1392,7 @@ class ActionResultHolder<void> : public UntypedActionResultHolderBase {
       const Action<F>& action,
       const typename Function<F>::ArgumentTuple& args) {
     action.Perform(args);
-    return NULL;
+    return new ActionResultHolder();
   }
 };