1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 
7 #include <string.h>
8 #include "nsTArray.h"
9 #include "nsXPCOM.h"
10 #include "nsDebug.h"
11 #include "mozilla/CheckedInt.h"
12 #include "mozilla/IntegerPrintfMacros.h"
13 
14 nsTArrayHeader nsTArrayHeader::sEmptyHdr = { 0, 0, 0 };
15 
16 bool
IsTwiceTheRequiredBytesRepresentableAsUint32(size_t aCapacity,size_t aElemSize)17 IsTwiceTheRequiredBytesRepresentableAsUint32(size_t aCapacity, size_t aElemSize)
18 {
19   using mozilla::CheckedUint32;
20   return ((CheckedUint32(aCapacity) * aElemSize) * 2).isValid();
21 }
22 
23 MOZ_NORETURN MOZ_COLD void
InvalidArrayIndex_CRASH(size_t aIndex,size_t aLength)24 InvalidArrayIndex_CRASH(size_t aIndex, size_t aLength)
25 {
26   MOZ_CRASH_UNSAFE_PRINTF(
27     "ElementAt(aIndex = %" PRIu64 ", aLength = %" PRIu64 ")",
28     static_cast<uint64_t>(aIndex), static_cast<uint64_t>(aLength));
29 }
30