summaryrefslogtreecommitdiff
path: root/tests/test-free.c
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff.email>2025-10-18 19:07:35 +0200
committerJörg Frings-Fürst <debian@jff.email>2025-10-18 19:07:35 +0200
commitfa23d938c040bc8af305a31fa874df55b2a02576 (patch)
tree9704e2f7bd8962ea8911cd6f4e2d37227d7eff2e /tests/test-free.c
parentdf9dbf9b0915e432a4a2c4182f60af36374eaaab (diff)
parent693ae7b71dfdd1a8146266b5794a71c0dbe5dff0 (diff)
Merge branch 'feature/upstream' into develop
Diffstat (limited to 'tests/test-free.c')
-rw-r--r--tests/test-free.c31
1 files changed, 13 insertions, 18 deletions
diff --git a/tests/test-free.c b/tests/test-free.c
index b0c084da..fff1c3a6 100644
--- a/tests/test-free.c
+++ b/tests/test-free.c
@@ -1,5 +1,5 @@
/* Test of free() function.
- Copyright (C) 2020-2024 Free Software Foundation, Inc.
+ Copyright (C) 2020-2025 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -37,14 +37,9 @@
a GCC optimization. Without it, when optimizing, GCC would "know" that errno
is unchanged by calling free(ptr), when ptr was the result of a malloc(...)
call in the same function. */
-static int
-get_errno (void)
-{
- volatile int err = errno;
- return err;
-}
-
-static int (* volatile get_errno_func) (void) = get_errno;
+void (*volatile my_free) (void *) = free;
+#undef free
+#define free my_free
int
main ()
@@ -53,11 +48,11 @@ main ()
{
errno = 1789; /* Liberté, égalité, fraternité. */
free (NULL);
- ASSERT_NO_STDIO (get_errno_func () == 1789);
+ ASSERT_NO_STDIO (errno == 1789);
}
{ /* Small memory allocations. */
#define N 10000
- void * volatile ptrs[N];
+ void *ptrs[N];
size_t i;
for (i = 0; i < N; i++)
ptrs[i] = malloc (15);
@@ -65,13 +60,13 @@ main ()
{
errno = 1789;
free (ptrs[i]);
- ASSERT_NO_STDIO (get_errno_func () == 1789);
+ ASSERT_NO_STDIO (errno == 1789);
}
#undef N
}
{ /* Medium memory allocations. */
#define N 1000
- void * volatile ptrs[N];
+ void *ptrs[N];
size_t i;
for (i = 0; i < N; i++)
ptrs[i] = malloc (729);
@@ -79,13 +74,13 @@ main ()
{
errno = 1789;
free (ptrs[i]);
- ASSERT_NO_STDIO (get_errno_func () == 1789);
+ ASSERT_NO_STDIO (errno == 1789);
}
#undef N
}
{ /* Large memory allocations. */
#define N 10
- void * volatile ptrs[N];
+ void *ptrs[N];
size_t i;
for (i = 0; i < N; i++)
ptrs[i] = malloc (5318153);
@@ -93,7 +88,7 @@ main ()
{
errno = 1789;
free (ptrs[i]);
- ASSERT_NO_STDIO (get_errno_func () == 1789);
+ ASSERT_NO_STDIO (errno == 1789);
}
#undef N
}
@@ -138,7 +133,7 @@ main ()
{
/* Do a large memory allocation. */
size_t big_size = 0x1000000;
- void * volatile ptr = malloc (big_size - 0x100);
+ void *ptr = malloc (big_size - 0x100);
char *ptr_aligned = (char *) ((uintptr_t) ptr & ~(pagesize - 1));
/* This large memory allocation allocated a memory area
from ptr_aligned to ptr_aligned + big_size.
@@ -171,7 +166,7 @@ main ()
which increases the number of VMAs by 1, which is supposed
to fail. */
free (ptr);
- ASSERT_NO_STDIO (get_errno_func () == 1789);
+ ASSERT_NO_STDIO (errno == 1789);
}
}
}