From 6a3ea69693839f0521620a7ace498b9c038924d4 Mon Sep 17 00:00:00 2001 From: Christopher Dykes Date: Tue, 19 Jul 2016 15:44:31 -0700 Subject: [PATCH] Handle small_vectors with 0 inline capacity correctly Summary: It is an error to attempt to get the size of a zero length array, such as `unsigned char[0]`, which is what you get if `MaxInline` has been passed in as 0. We can work around this by simply defining `InlineStorageType` to be `void*` if the size is exactly 0, which will result in the capacity correctly being stored out of line. Reviewed By: yfeldblum Differential Revision: D3572898 fbshipit-source-id: c96bb7cc6a890044bb74b0f6d5238c503552ee25 --- folly/small_vector.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/folly/small_vector.h b/folly/small_vector.h index 042961bc..da4547b4 100644 --- a/folly/small_vector.h +++ b/folly/small_vector.h @@ -1038,14 +1038,20 @@ private: } FOLLY_PACK_ATTR; #if (FOLLY_X64 || FOLLY_PPC64) - typedef unsigned char InlineStorageType[sizeof(value_type) * MaxInline]; + typedef unsigned char InlineStorageDataType[sizeof(value_type) * MaxInline]; #else typedef typename std::aligned_storage< sizeof(value_type) * MaxInline, alignof(value_type) - >::type InlineStorageType; + >::type InlineStorageDataType; #endif + typedef typename std::conditional< + sizeof(value_type) * MaxInline != 0, + InlineStorageDataType, + void* + >::type InlineStorageType; + static bool const kHasInlineCapacity = sizeof(HeapPtrWithCapacity) < sizeof(InlineStorageType); -- 2.34.1