aboutsummaryrefslogtreecommitdiffstats
path: root/libpatch_append_to_patch__.c
blob: cf54c6f7cd87946ef0187bbe1803104540fd9e2e (plain) (blame)
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
/* See LICENSE file for copyright and license details. */
#include "common.h"


int
libpatch_append_to_patch__(struct libpatch_patch **patch, size_t *patchlen, size_t *size,
                           size_t stroff, size_t strlen, int type)
{
	void *new;
	if (*patchlen < *size) {
		if (*size > SIZE_MAX / sizeof(**patch) - 70) {
			errno = ENOMEM;
			return -1;
		}
		new = realloc(*patch, (*size + 70) * sizeof(**patch));
		if (!new)
			return -1;
		*patch = new;
		*size += 70;
		memset(&(*patch)[*patchlen], 0, 70 * sizeof(**patch));
	}
	(*patch)[*patchlen].type = type;
	(*patch)[*patchlen].text_offset = stroff;
	(*patch)[*patchlen].text_length = strlen;
	(*patch)[*patchlen].lf_terminated = 1;
	*patchlen += 1;
	return 0;
}