2 * Copyright (C) 2010-2024 Free Software Foundation, Inc.
3 * Written by Eric Blake
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>. */
22 #include "signature.h"
23 SIGNATURE_CHECK (strnlen
, size_t, (char const *, size_t));
27 #include "zerosize-ptr.h"
34 char *page_boundary
= (char *) zerosize_ptr ();
37 page_boundary
= malloc (0x1000);
38 ASSERT (page_boundary
);
39 page_boundary
+= 0x1000;
42 /* Basic behavior tests. */
43 ASSERT (strnlen ("a", 0) == 0);
44 ASSERT (strnlen ("a", 1) == 1);
45 ASSERT (strnlen ("a", 2) == 1);
46 ASSERT (strnlen ("", 0x100000) == 0);
48 /* Memory fence and alignment testing. */
49 for (i
= 0; i
< 512; i
++)
51 char *start
= page_boundary
- i
;
53 memset (start
, 'x', i
);
59 ASSERT (strnlen (start
, i
+ j
) == j
);
61 ASSERT (strnlen (start
, i
) == j
);
62 ASSERT (strnlen (start
, j
) == j
);
67 return test_exit_status
;