aboutsummaryrefslogtreecommitdiff
path: root/src/alloc.c
blob: 868265613ca4b285da02c23e4878977bad82e96c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <assert.h>
#include <errno.h>
#include <stdint.h>
#include <stdlib.h>

#include "alloc.h"
#include "errors.h"

void *
bufalloc(void *ptr, size_t nmemb, size_t size)
{
	assert(nmemb * size != 0);
	if (size > SIZE_MAX / nmemb) {
		errno = EOVERFLOW;
		err("%s:", __func__);
	}
	if ((ptr = realloc(ptr, nmemb * size)) == NULL)
		err("%s:", __func__);
	return ptr;
}