mailing list of musl libc
 help / color / mirror / code / Atom feed
ce3adde49aed53b004718a5857f84a4e00aea28e blob 645 bytes (raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
 
#define _BSD_SOURCE
#include <errno.h>
#include <stdlib.h>
#include <string.h>

void *recallocarray(void *ptr, size_t om, size_t m, size_t n)
{
	void *newptr;
	size_t old_size, new_size;

	if (n && m > -1 / n) {
		errno = ENOMEM;
		return 0;
	}
	new_size = m * n;

	if (n && om > -1 / n) {
		errno = EINVAL;
		return 0;
	}
	old_size = om * n;

	newptr = calloc(m, n);
	if (!newptr)
		return ptr;

	if (new_size <= old_size) {
		memcpy((char *) newptr, ptr, new_size);
	}
	else {
		memcpy((char *) newptr, ptr, old_size);
		memset((char *) newptr + old_size, 0, new_size - old_size);
	}

	memset(ptr, 0, old_size);
	free(ptr);

	return newptr;
}
debug log:

solving ce3adde4 ...
found ce3adde4 in https://inbox.vuxu.org/musl/20200802225426.32002-1-ariadne@dereferenced.org/

applying [1/1] https://inbox.vuxu.org/musl/20200802225426.32002-1-ariadne@dereferenced.org/
diff --git a/src/malloc/recallocarray.c b/src/malloc/recallocarray.c
new file mode 100644
index 00000000..ce3adde4

Checking patch src/malloc/recallocarray.c...
Applied patch src/malloc/recallocarray.c cleanly.

index at:
100644 ce3adde49aed53b004718a5857f84a4e00aea28e	src/malloc/recallocarray.c

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).