aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBehdad Esfahbod <behdad@behdad.org>2016-10-30 05:30:47 -0700
committerGitHub <noreply@github.com>2016-10-30 05:30:47 -0700
commit64f78562d2003eb7cacaaa86a398cbd41881ba6f (patch)
tree4cc9c424a30038336a9b2959e0f972f51992d44f
parent6e984975bf31b5a94fa3337dd56ab687bcee91c1 (diff)
parent427f36e967318da60e86404a638bcecb10c97dbd (diff)
downloadsfntly-64f78562d2003eb7cacaaa86a398cbd41881ba6f.tar.gz
Merge pull request #62 from leizleiz/leizleiz-cfi
Fix invalid cast found by Control Flow Integrity.
-rw-r--r--cpp/src/sfntly/port/refcount.h21
1 files changed, 9 insertions, 12 deletions
diff --git a/cpp/src/sfntly/port/refcount.h b/cpp/src/sfntly/port/refcount.h
index eed5162..6353b08 100644
--- a/cpp/src/sfntly/port/refcount.h
+++ b/cpp/src/sfntly/port/refcount.h
@@ -99,22 +99,18 @@
namespace sfntly {
+template <typename T>
+class Ptr;
+
class RefCount {
public:
// Make gcc -Wnon-virtual-dtor happy.
virtual ~RefCount() {}
- virtual size_t AddRef() const = 0;
- virtual size_t Release() const = 0;
-};
-
-template <typename T>
-class NoAddRefRelease : public T {
- public:
- NoAddRefRelease();
- ~NoAddRefRelease();
-
private:
+ template <typename T>
+ friend class Ptr;
+
virtual size_t AddRef() const = 0;
virtual size_t Release() const = 0;
};
@@ -142,6 +138,7 @@ class RefCounted : virtual public RefCount {
return *this;
}
+ private:
virtual size_t AddRef() const {
size_t new_count = AtomicIncrement(&ref_count_);
DEBUG_OUTPUT("A ");
@@ -224,8 +221,8 @@ class Ptr {
return *p_; // It can throw!
}
- NoAddRefRelease<T>* operator->() const {
- return (NoAddRefRelease<T>*)p_; // It can throw!
+ T* operator->() const {
+ return p_; // It can throw!
}
bool operator!() const {