Compare commits
2 Commits
4c76f6bf01
...
ffa0805d58
Author | SHA1 | Date |
---|---|---|
Ariadne Conill | ffa0805d58 | |
Ariadne Conill | c1579d381c |
|
@ -137,3 +137,23 @@ pkgconf_strndup(const char *src, size_t len)
|
||||||
{
|
{
|
||||||
return strndup(src, len);
|
return strndup(src, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef HAVE_REALLOCARRAY
|
||||||
|
void *
|
||||||
|
reallocarray(void *ptr, size_t m, size_t n)
|
||||||
|
{
|
||||||
|
if (n && m > -1 / n)
|
||||||
|
{
|
||||||
|
errno = ENOMEM;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return realloc(ptr, m * n);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void *
|
||||||
|
pkgconf_reallocarray(void *ptr, size_t m, size_t n)
|
||||||
|
{
|
||||||
|
return reallocarray(ptr, m, n);
|
||||||
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@ extern "C" {
|
||||||
PKGCONF_API extern size_t pkgconf_strlcpy(char *dst, const char *src, size_t siz);
|
PKGCONF_API extern size_t pkgconf_strlcpy(char *dst, const char *src, size_t siz);
|
||||||
PKGCONF_API extern size_t pkgconf_strlcat(char *dst, const char *src, size_t siz);
|
PKGCONF_API extern size_t pkgconf_strlcat(char *dst, const char *src, size_t siz);
|
||||||
PKGCONF_API extern char *pkgconf_strndup(const char *src, size_t len);
|
PKGCONF_API extern char *pkgconf_strndup(const char *src, size_t len);
|
||||||
|
PKGCONF_API extern void *pkgconf_reallocarray(void *ptr, size_t m, size_t n);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -128,7 +128,7 @@ pkgconf_cache_add(pkgconf_client_t *client, pkgconf_pkg_t *pkg)
|
||||||
pkg->flags |= PKGCONF_PKG_PROPF_CACHED;
|
pkg->flags |= PKGCONF_PKG_PROPF_CACHED;
|
||||||
|
|
||||||
++client->cache_count;
|
++client->cache_count;
|
||||||
client->cache_table = reallocarray(client->cache_table,
|
client->cache_table = pkgconf_reallocarray(client->cache_table,
|
||||||
client->cache_count, sizeof (void *));
|
client->cache_count, sizeof (void *));
|
||||||
client->cache_table[client->cache_count - 1] = pkg;
|
client->cache_table[client->cache_count - 1] = pkg;
|
||||||
|
|
||||||
|
@ -181,7 +181,7 @@ pkgconf_cache_remove(pkgconf_client_t *client, pkgconf_pkg_t *pkg)
|
||||||
}
|
}
|
||||||
|
|
||||||
client->cache_count--;
|
client->cache_count--;
|
||||||
client->cache_table = reallocarray(client->cache_table,
|
client->cache_table = pkgconf_reallocarray(client->cache_table,
|
||||||
client->cache_count, sizeof(void *));
|
client->cache_count, sizeof(void *));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -214,7 +214,7 @@ pkgconf_cache_free(pkgconf_client_t *client)
|
||||||
pkgconf_pkg_t **cache_table;
|
pkgconf_pkg_t **cache_table;
|
||||||
size_t i, count;
|
size_t i, count;
|
||||||
|
|
||||||
cache_table = reallocarray(NULL, client->cache_count, sizeof (void *));
|
cache_table = pkgconf_reallocarray(NULL, client->cache_count, sizeof (void *));
|
||||||
memcpy(cache_table, client->cache_table,
|
memcpy(cache_table, client->cache_table,
|
||||||
client->cache_count * sizeof (void *));
|
client->cache_count * sizeof (void *));
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue