26static inline void *
gv_calloc(
size_t nmemb,
size_t size) {
28 if (nmemb > 0 &&
SIZE_MAX / nmemb < size) {
30 "integer overflow when trying to allocate "
36 void *p = calloc(nmemb, size);
37 if (nmemb > 0 && size > 0 && p ==
NULL) {
39 "out of memory when trying to allocate %" PRISIZE_T " bytes\n",
49static inline void *
gv_realloc(
void *ptr,
size_t old_size,
size_t new_size) {
57 void *p = realloc(ptr, new_size);
60 "out of memory when trying to allocate %" PRISIZE_T " bytes\n",
66 if (new_size > old_size) {
67 memset((
char *)p + old_size, 0, new_size - old_size);
73static inline void *
gv_recalloc(
void *ptr,
size_t old_nmemb,
size_t new_nmemb,
76 assert(size > 0 &&
"attempt to allocate array of 0-sized elements");
77 assert(old_nmemb <
SIZE_MAX / size &&
"claimed previous extent is too large");
82 "integer overflow when trying to allocate %" PRISIZE_T
88 return gv_realloc(ptr, old_nmemb * size, new_nmemb * size);
94#if defined(__cplusplus) && defined(__CYGWIN__)
96extern char *strdup(
const char *
s1);
97extern char *strndup(
const char *
s1,
size_t n);
103 char *
copy = strdup(original);
106 "out of memory when trying to allocate %" PRISIZE_T " bytes\n",
107 strlen(original) + 1);
114static inline char *
gv_strndup(
const char *original,
size_t length) {
119#if defined(_MSC_VER) || defined(__MINGW32__)
123 const char *end = (
const char *)memchr(original,
'\0', length);
125 length = (size_t)(end - original);
132 "integer overflow when trying to allocate %" PRISIZE_T
139 memcpy(
copy, original, length);
145 copy = strndup(original, length);
150 "out of memory when trying to allocate %" PRISIZE_T " bytes\n",
Agobj_t * copy(Agraph_t *g, Agobj_t *obj)
static void * gv_recalloc(void *ptr, size_t old_nmemb, size_t new_nmemb, size_t size)
static char * gv_strdup(const char *original)
static void * gv_realloc(void *ptr, size_t old_size, size_t new_size)
static void * gv_calloc(size_t nmemb, size_t size)
static char * gv_strndup(const char *original, size_t length)
static void * gv_alloc(size_t size)
static NORETURN void graphviz_exit(int status)
NEATOPROCS_API void s1(graph_t *, node_t *)
#define PRISIZE_T
PRIu64 alike for printing size_t