nsTArray.cpp 932 B

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