From 28747969cd2530114759e9d61ee711b887189d72 Mon Sep 17 00:00:00 2001 From: hbos Date: Mon, 21 Nov 2016 09:17:41 -0800 Subject: [PATCH] RTCStats operator== bugfix a == b would return true if a.member is defined even if b.member is undefined if their values were equal. We would say that b does not have a value in that case but its value_ member would still be initialized to something that is being compared to. Bugfix makes sure not to do value comparison in this case if b is undefined. BUG=chromium:627816 Review-Url: https://codereview.webrtc.org/2517163002 Cr-Commit-Position: refs/heads/master@{#15172} --- webrtc/api/stats/rtcstats.h | 2 ++ webrtc/stats/rtcstats_unittest.cc | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/webrtc/api/stats/rtcstats.h b/webrtc/api/stats/rtcstats.h index d23e928fad..aea47c22ad 100644 --- a/webrtc/api/stats/rtcstats.h +++ b/webrtc/api/stats/rtcstats.h @@ -271,6 +271,8 @@ class RTCStatsMember : public RTCStatsMemberInterface { static_cast&>(other); if (!is_defined_) return !other_t.is_defined(); + if (!other.is_defined()) + return false; return value_ == other_t.value_; } std::string ValueToString() const override; diff --git a/webrtc/stats/rtcstats_unittest.cc b/webrtc/stats/rtcstats_unittest.cc index f24519467c..7854355744 100644 --- a/webrtc/stats/rtcstats_unittest.cc +++ b/webrtc/stats/rtcstats_unittest.cc @@ -172,6 +172,12 @@ TEST(RTCStatsTest, EqualityOperator) { RTCChildStats child("childId", 42); RTCGrandChildStats grandchild("grandchildId", 42); EXPECT_NE(child, grandchild); + + RTCChildStats stats_with_defined_member("leId", 0); + stats_with_defined_member.child_int = 0; + RTCChildStats stats_with_undefined_member("leId", 0); + EXPECT_NE(stats_with_defined_member, stats_with_undefined_member); + EXPECT_NE(stats_with_undefined_member, stats_with_defined_member); } TEST(RTCStatsTest, RTCStatsGrandChild) {