From 460db498a35c7ee11532f5711c7d749f5decf1dc Mon Sep 17 00:00:00 2001 From: Nathan Froyd Date: Thu, 18 Feb 2016 12:07:03 -0500 Subject: [PATCH] Bug 1249389 - part 3 - assert the size of nsZipItemPtr's storage type; r=erahm The only uses of this class use a template argument with a size of |char| (uint8_t and char), and the class isn't designed to accomodate template arguments of larger size (e.g. the implementation of Forget() neglects to divide by sizeof(T) for allocating a return buffer). Let's enforce this with a static_assert. This change makes the class safer to use and also makes future changes simpler to reason about. --- modules/libjar/nsZipArchive.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/libjar/nsZipArchive.h b/modules/libjar/nsZipArchive.h index d29325b67b4a..e8ed787c800f 100644 --- a/modules/libjar/nsZipArchive.h +++ b/modules/libjar/nsZipArchive.h @@ -350,6 +350,10 @@ protected: template class nsZipItemPtr final : public nsZipItemPtr_base { + static_assert(sizeof(T) == sizeof(char), + "This class cannot be used with larger T without re-examining" + " a number of assumptions."); + public: nsZipItemPtr(nsZipArchive *aZip, const char *aEntryName, bool doCRC = false) : nsZipItemPtr_base(aZip, aEntryName, doCRC) { } /**