1
0

memory.cc 638 B

123456789101112131415161718192021222324252627282930
  1. // Copyright 2014 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "butil/process/memory.h"
  5. namespace butil {
  6. // Defined in memory_mac.mm for Mac.
  7. #if !defined(OS_MACOSX)
  8. bool UncheckedCalloc(size_t num_items, size_t size, void** result) {
  9. const size_t alloc_size = num_items * size;
  10. // Overflow check
  11. if (size && ((alloc_size / size) != num_items)) {
  12. *result = NULL;
  13. return false;
  14. }
  15. if (!UncheckedMalloc(alloc_size, result))
  16. return false;
  17. memset(*result, 0, alloc_size);
  18. return true;
  19. }
  20. #endif
  21. }