Use reallocarray(3)
This commit is contained in:
parent
f346f61ea0
commit
55c4755943
4
daemon.h
4
daemon.h
@ -38,7 +38,9 @@ static inline void prependClear(void) {
|
|||||||
static inline int prependAdd(const char *command) {
|
static inline int prependAdd(const char *command) {
|
||||||
if (prepend.len == prepend.cap) {
|
if (prepend.len == prepend.cap) {
|
||||||
size_t cap = (prepend.cap ? prepend.cap * 2 : 8);
|
size_t cap = (prepend.cap ? prepend.cap * 2 : 8);
|
||||||
void *ptr = realloc(prepend.commands, sizeof(*prepend.commands) * cap);
|
void *ptr = reallocarray(
|
||||||
|
prepend.commands, cap, sizeof(*prepend.commands)
|
||||||
|
);
|
||||||
if (!ptr) return -1;
|
if (!ptr) return -1;
|
||||||
prepend.cap = cap;
|
prepend.cap = cap;
|
||||||
prepend.commands = ptr;
|
prepend.commands = ptr;
|
||||||
|
@ -82,7 +82,7 @@ int serviceAdd(const char *name, const char *command) {
|
|||||||
|
|
||||||
if (services.len == services.cap) {
|
if (services.len == services.cap) {
|
||||||
size_t cap = (services.cap ? services.cap * 2 : 8);
|
size_t cap = (services.cap ? services.cap * 2 : 8);
|
||||||
void *ptr = realloc(services.ptr, sizeof(*services.ptr) * cap);
|
void *ptr = reallocarray(services.ptr, cap, sizeof(*services.ptr));
|
||||||
if (!ptr) return -1;
|
if (!ptr) return -1;
|
||||||
services.cap = cap;
|
services.cap = cap;
|
||||||
services.ptr = ptr;
|
services.ptr = ptr;
|
||||||
|
Loading…
Reference in New Issue
Block a user