#include <stdlib.h>
#include <support/support.h>
+#include <libc-diag.h>
#define SIZE 4096
call_free (void *ptr)
{
free (ptr);
+#if __GNUC_PREREQ (12, 0)
+ /* Ignore a valid warning about using a pointer made indeterminate
+ by a prior call to free(). */
+ DIAG_IGNORE_NEEDS_COMMENT (12, "-Wuse-after-free");
+#endif
*(size_t *)(ptr - sizeof (size_t)) = 1;
+#if __GNUC_PREREQ (12, 0)
+ DIAG_POP_NEEDS_COMMENT;
+#endif
}
int
merror ("errno is not set correctly.");
DIAG_POP_NEEDS_COMMENT;
+#if __GNUC_PREREQ (12, 0)
+ /* Ignore a valid warning about using a pointer made indeterminate
+ by a prior call to realloc(). */
+ DIAG_IGNORE_NEEDS_COMMENT (12, "-Wuse-after-free");
+#endif
free (p);
+#if __GNUC_PREREQ (12, 0)
+ DIAG_POP_NEEDS_COMMENT;
+#endif
p = malloc (512);
if (p == NULL)
merror ("errno is not set correctly.");
DIAG_POP_NEEDS_COMMENT;
+#if __GNUC_PREREQ (12, 0)
+ /* Ignore a valid warning about using a pointer made indeterminate
+ by a prior call to realloc(). */
+ DIAG_IGNORE_NEEDS_COMMENT (12, "-Wuse-after-free");
+#endif
free (p);
+#if __GNUC_PREREQ (12, 0)
+ DIAG_POP_NEEDS_COMMENT;
+#endif
free (q);
return errors != 0;
DIAG_POP_NEEDS_COMMENT;
#endif
TEST_VERIFY (errno == ENOMEM);
+#if __GNUC_PREREQ (12, 0)
+ /* Ignore a warning about using a pointer made indeterminate by
+ a prior call to realloc(). */
+ DIAG_IGNORE_NEEDS_COMMENT (12, "-Wuse-after-free");
+#endif
free (ptr_to_realloc);
+#if __GNUC_PREREQ (12, 0)
+ DIAG_POP_NEEDS_COMMENT;
+#endif
for (size_t nmemb = 1; nmemb <= 8; nmemb *= 2)
if ((size % nmemb) == 0)
test_setup ();
TEST_VERIFY (reallocarray (ptr_to_realloc, nmemb, size / nmemb) == NULL);
TEST_VERIFY (errno == ENOMEM);
+#if __GNUC_PREREQ (12, 0)
+ /* Ignore a warning about using a pointer made indeterminate by
+ a prior call to realloc(). */
+ DIAG_IGNORE_NEEDS_COMMENT (12, "-Wuse-after-free");
+#endif
free (ptr_to_realloc);
+#if __GNUC_PREREQ (12, 0)
+ DIAG_POP_NEEDS_COMMENT;
+#endif
ptr_to_realloc = malloc (16);
TEST_VERIFY_EXIT (ptr_to_realloc != NULL);
test_setup ();
TEST_VERIFY (reallocarray (ptr_to_realloc, size / nmemb, nmemb) == NULL);
TEST_VERIFY (errno == ENOMEM);
+#if __GNUC_PREREQ (12, 0)
+ /* Ignore a warning about using a pointer made indeterminate by
+ a prior call to realloc(). */
+ DIAG_IGNORE_NEEDS_COMMENT (12, "-Wuse-after-free");
+#endif
free (ptr_to_realloc);
+#if __GNUC_PREREQ (12, 0)
+ DIAG_POP_NEEDS_COMMENT;
+#endif
}
else
break;
static void
verbose_free (void *buf)
{
- free (buf);
printf ("free (%p)\n", buf);
+ free (buf);
}
static int
if (ok == 0)
merror ("first 16 bytes were not correct after failed realloc");
+#if __GNUC_PREREQ (12, 0)
+ /* Ignore a valid warning about using a pointer made indeterminate
+ by a prior call to realloc(). */
+ DIAG_IGNORE_NEEDS_COMMENT (12, "-Wuse-after-free");
+#endif
/* realloc (p, 0) frees p (C89) and returns NULL (glibc). */
p = realloc (p, 0);
+#if __GNUC_PREREQ (12, 0)
+ DIAG_POP_NEEDS_COMMENT;
+#endif
if (p != NULL)
merror ("realloc (p, 0) returned non-NULL.");
char file_path[PATH_MAX];
ssize_t file_path_length
= readlink (proc_fd_path, file_path, sizeof (file_path));
- free (proc_fd_path);
if (file_path_length < 0)
FAIL_EXIT1 ("readlink (%s, %p, %zu)", proc_fd_path, file_path,
sizeof (file_path));
+
+ free (proc_fd_path);
file_path[file_path_length] = '\0';
TEST_COMPARE_STRING (file_path, "/dev/null");
}