aboutsummaryrefslogtreecommitdiff
path: root/contrib/expat/tests/memcheck.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/expat/tests/memcheck.c')
-rw-r--r--contrib/expat/tests/memcheck.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/contrib/expat/tests/memcheck.c b/contrib/expat/tests/memcheck.c
index 41355f6c8d91..de9254997214 100644
--- a/contrib/expat/tests/memcheck.c
+++ b/contrib/expat/tests/memcheck.c
@@ -6,8 +6,9 @@
\___/_/\_\ .__/ \__,_|\__|
|_| XML parser
- Copyright (c) 1997-2000 Thai Open Source Software Center Ltd
- Copyright (c) 2000-2017 Expat development team
+ Copyright (c) 2017 Rhodri James <rhodri@wildebeest.org.uk>
+ Copyright (c) 2017-2023 Sebastian Pipping <sebastian@pipping.org>
+ Copyright (c) 2022 Sean McBride <sean@rogue-research.com>
Licensed under the MIT license:
Permission is hereby granted, free of charge, to any person obtaining
@@ -49,12 +50,13 @@ typedef struct allocation_entry {
static AllocationEntry *alloc_head = NULL;
static AllocationEntry *alloc_tail = NULL;
-static AllocationEntry *find_allocation(void *ptr);
+static AllocationEntry *find_allocation(const void *ptr);
/* Allocate some memory and keep track of it. */
void *
tracking_malloc(size_t size) {
- AllocationEntry *entry = malloc(sizeof(AllocationEntry));
+ AllocationEntry *const entry
+ = (AllocationEntry *)malloc(sizeof(AllocationEntry));
if (entry == NULL) {
printf("Allocator failure\n");
@@ -82,7 +84,7 @@ tracking_malloc(size_t size) {
}
static AllocationEntry *
-find_allocation(void *ptr) {
+find_allocation(const void *ptr) {
AllocationEntry *entry;
for (entry = alloc_head; entry != NULL; entry = entry->next) {
@@ -140,7 +142,7 @@ tracking_realloc(void *ptr, size_t size) {
entry = find_allocation(ptr);
if (entry == NULL) {
printf("Attempting to realloc unallocated memory at %p\n", ptr);
- entry = malloc(sizeof(AllocationEntry));
+ entry = (AllocationEntry *)malloc(sizeof(AllocationEntry));
if (entry == NULL) {
printf("Reallocator failure\n");
return NULL;
@@ -162,12 +164,11 @@ tracking_realloc(void *ptr, size_t size) {
alloc_tail = entry;
}
} else {
- entry->allocation = realloc(ptr, size);
- if (entry->allocation == NULL) {
- /* Realloc semantics say the original is still allocated */
- entry->allocation = ptr;
+ void *const reallocated = realloc(ptr, size);
+ if (reallocated == NULL) {
return NULL;
}
+ entry->allocation = reallocated;
}
entry->num_bytes = size;