]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
b66de1f9 RC |
2 | /*** |
3 | This file is part of systemd. | |
4 | ||
5 | Copyright 2010 Lennart Poettering | |
6 | ||
7 | systemd is free software; you can redistribute it and/or modify it | |
8 | under the terms of the GNU Lesser General Public License as published by | |
9 | the Free Software Foundation; either version 2.1 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | systemd is distributed in the hope that it will be useful, but | |
13 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | Lesser General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU Lesser General Public License | |
18 | along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
19 | ***/ | |
20 | ||
21 | #include "alloc-util.h" | |
22 | #include "macro.h" | |
23 | #include "util.h" | |
24 | ||
25 | static void test_alloca(void) { | |
26 | static const uint8_t zero[997] = { }; | |
27 | char *t; | |
28 | ||
29 | t = alloca_align(17, 512); | |
30 | assert_se(!((uintptr_t)t & 0xff)); | |
31 | memzero(t, 17); | |
32 | ||
33 | t = alloca0_align(997, 1024); | |
34 | assert_se(!((uintptr_t)t & 0x1ff)); | |
35 | assert_se(!memcmp(t, zero, 997)); | |
36 | } | |
37 | ||
38 | static void test_memdup_multiply(void) { | |
39 | int org[] = {1, 2, 3}; | |
40 | int *dup; | |
41 | ||
42 | dup = (int*)memdup_multiply(org, sizeof(int), 3); | |
43 | ||
44 | assert_se(dup); | |
45 | assert_se(dup[0] == 1); | |
46 | assert_se(dup[1] == 2); | |
47 | assert_se(dup[2] == 3); | |
48 | free(dup); | |
49 | } | |
50 | ||
51 | int main(int argc, char *argv[]) { | |
52 | test_alloca(); | |
53 | test_memdup_multiply(); | |
54 | ||
55 | return 0; | |
56 | } |