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