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.
This commit is contained in:
Nathan Froyd 2016-02-18 12:07:03 -05:00
parent 42baa283e9
commit 22fa651d41

View File

@ -350,6 +350,10 @@ protected:
template <class T>
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) { }
/**