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:
@@ -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;
|
||||
|
||||
|
Reference in New Issue
Block a user