Fix stack alignment for SkAutoSTArray
The alignment for the inline memory was incorrect for T with
alignof(T) > alignof(T*). This would be things like closures
and std::function on mac. So, rare, but still a bug.
Change-Id: I867f688bdb28ad489b465f1ae379be6dc0247b18
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/629344
Reviewed-by: Brian Salomon <bsalomon@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
Commit-Queue: Herb Derby <herb@google.com>
diff --git a/include/private/SkTemplates.h b/include/private/SkTemplates.h
index 53512b8..f335b81 100644
--- a/include/private/SkTemplates.h
+++ b/include/private/SkTemplates.h
@@ -241,10 +241,9 @@
static const int kCount = kCountRequested;
#endif
- int fCount;
- T* fArray;
- // since we come right after fArray, fStorage should be properly aligned
- char fStorage[kCount * sizeof(T)];
+ int fCount;
+ T* fArray;
+ alignas(T) char fStorage[kCount * sizeof(T)];
};
/** Manages an array of T elements, freeing the array in the destructor.