1 /*
2 * Copyright (c) 2021, Alliance for Open Media. All rights reserved.
3 *
4 * This source code is subject to the terms of the BSD 2 Clause License and
5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6 * was not distributed with this source code in the LICENSE file, you can
7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8 * Media Patent License 1.0 was not distributed with this source code in the
9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10 */
11
12 #include "aom_mem/aom_mem.h"
13
14 #include <cstdio>
15 #include <cstddef>
16
17 #include "gtest/gtest.h"
18
TEST(AomMemTest,Overflow)19 TEST(AomMemTest, Overflow) {
20 // Allocations are aligned > 1 so SIZE_MAX should always fail.
21 ASSERT_EQ(aom_malloc(SIZE_MAX), nullptr);
22 ASSERT_EQ(aom_calloc(1, SIZE_MAX), nullptr);
23 ASSERT_EQ(aom_calloc(32, SIZE_MAX / 32), nullptr);
24 ASSERT_EQ(aom_calloc(SIZE_MAX, SIZE_MAX), nullptr);
25 ASSERT_EQ(aom_memalign(1, SIZE_MAX), nullptr);
26 ASSERT_EQ(aom_memalign(64, SIZE_MAX), nullptr);
27 ASSERT_EQ(aom_memalign(64, SIZE_MAX - 64), nullptr);
28 ASSERT_EQ(aom_memalign(64, SIZE_MAX - 64 - sizeof(size_t) + 2), nullptr);
29 }
30
TEST(AomMemTest,NullParams)31 TEST(AomMemTest, NullParams) {
32 ASSERT_EQ(aom_memset16(nullptr, 0, 0), nullptr);
33 aom_free(nullptr);
34 }
35