Explicitly pass reference in hb_auto_t constructor
authorBehdad Esfahbod <behdad@behdad.org>
Tue, 28 Aug 2018 18:02:00 +0000 (11:02 -0700)
committerBehdad Esfahbod <behdad@behdad.org>
Tue, 28 Aug 2018 18:07:24 +0000 (11:07 -0700)
Fixes clang bots as well as fuzzer issue.

src/hb-dsalgs.hh

index ec5708e..8c91074 100644 (file)
@@ -492,7 +492,14 @@ template <typename Type>
 struct hb_auto_t : Type
 {
   hb_auto_t (void) { Type::init (); }
-  template <typename T1> hb_auto_t (T1 t1) { Type::init (t1); }
+  /* Explicitly allow the following only for pointer and references,
+   * to avoid any accidental copies.
+   *
+   * Apparently if we template for all types, then gcc seems to
+   * capture a reference argument in the type, but clang doesn't,
+   * causing unwanted copies and bugs that come with it. */
+  template <typename T1> hb_auto_t (T1 *t1) { Type::init (t1); }
+  template <typename T1> hb_auto_t (T1 &t1) { Type::init (t1); }
   ~hb_auto_t (void) { Type::fini (); }
   private: /* Hide */
   void init (void) {}