Do variable length arrays the C99 way

Variable length arrays are supported by C99, but having it denoted as "1" confused the compiler and is not defined.

Note that because we don't get the inferred NULL terminator, we have to increase the malloc size by one.
This commit is contained in:
Rose
2023-05-18 14:49:45 -04:00
parent 64b666471a
commit 7fd680c983
6 changed files with 10 additions and 10 deletions

View File

@@ -34,7 +34,7 @@
/* Trivial reference-counted strings. */
struct rcstr {
int refcnt;
char str[1]; /* actually bigger */
char str[];
};
/*
@@ -62,8 +62,7 @@ sudo_rcstr_alloc(size_t len)
struct rcstr *rcs;
debug_decl(sudo_rcstr_dup, SUDO_DEBUG_UTIL);
/* Note: sizeof(struct rcstr) includes space for the NUL */
rcs = malloc(sizeof(struct rcstr) + len);
rcs = malloc(sizeof(struct rcstr) + len + 1);
if (rcs == NULL)
return NULL;