Skip to content

Commit 3bdd221

Browse files
authored
Merge pull request #266 from AtariDreams/c99
Do variable length arrays the C99 way
2 parents 69b486d + 7fd680c commit 3bdd221

6 files changed

Lines changed: 10 additions & 10 deletions

File tree

include/sudo_event.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ typedef void (*sudo_ev_callback_t)(int fd, int what, void *closure);
6464
struct sudo_ev_siginfo_container {
6565
void *closure;
6666
siginfo_t *siginfo;
67-
char si_buf[1];
67+
char si_buf[];
6868
};
6969

7070
/* Member of struct sudo_event_base. */

lib/util/event.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ sudo_ev_set_v1(struct sudo_event *ev, int fd, short events,
291291
/* For SUDO_EV_SIGINFO we use a container to store closure + siginfo_t */
292292
if (ISSET(events, SUDO_EV_SIGINFO)) {
293293
struct sudo_ev_siginfo_container *container =
294-
malloc(sizeof(*container) + sizeof(siginfo_t) - 1);
294+
malloc(sizeof(*container) + sizeof(siginfo_t));
295295
if (container == NULL) {
296296
sudo_debug_printf(SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO,
297297
"%s: unable to allocate siginfo container", __func__);

lib/util/rcstr.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
/* Trivial reference-counted strings. */
3535
struct rcstr {
3636
int refcnt;
37-
char str[1]; /* actually bigger */
37+
char str[];
3838
};
3939

4040
/*
@@ -62,8 +62,7 @@ sudo_rcstr_alloc(size_t len)
6262
struct rcstr *rcs;
6363
debug_decl(sudo_rcstr_dup, SUDO_DEBUG_UTIL);
6464

65-
/* Note: sizeof(struct rcstr) includes space for the NUL */
66-
rcs = malloc(sizeof(struct rcstr) + len);
65+
rcs = malloc(sizeof(struct rcstr) + len + 1);
6766
if (rcs == NULL)
6867
return NULL;
6968

plugins/sudoers/canon_path.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ static struct rbtree *canon_cache;
4141
* resolved path. The resolved path is directly embedded into the
4242
* struct so that we can find the start of the struct cache_item
4343
* given the value of resolved. Storage for pathname is embedded
44-
* at the end, after resolved.
44+
* at the end with resolved.
4545
*/
4646
struct cache_item {
4747
unsigned int refcnt;
4848
char *pathname;
49-
char resolved[1]; /* actually bigger */
49+
char resolved[];
5050
};
5151

5252
/*
@@ -150,7 +150,8 @@ canon_path(const char *inpath)
150150
resolved = realpath(inpath, resbuf);
151151

152152
inlen = strlen(inpath);
153-
item_size = sizeof(*item) + inlen + 1;
153+
/* one for NULL terminator of resolved, one for NULL terminator of pathname */
154+
item_size = sizeof(*item) + inlen + 2;
154155
if (resolved != NULL) {
155156
reslen = strlen(resolved);
156157
item_size += reslen;

plugins/sudoers/ldap_conf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ sudo_ldap_parse_keyword(const char *keyword, const char *value,
452452

453453
if (len > 0) {
454454
head = (struct ldap_config_str_list *)cur->valp;
455-
if ((str = malloc(sizeof(*str) + len)) == NULL) {
455+
if ((str = malloc(sizeof(*str) + len + 1)) == NULL) {
456456
sudo_warnx(U_("%s: %s"), __func__, U_("unable to allocate memory"));
457457
debug_return_bool(false);
458458
}

plugins/sudoers/sudo_ldap_conf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ struct ldap_config_table {
4444

4545
struct ldap_config_str {
4646
STAILQ_ENTRY(ldap_config_str) entries;
47-
char val[1];
47+
char val[];
4848
};
4949
STAILQ_HEAD(ldap_config_str_list, ldap_config_str);
5050

0 commit comments

Comments
 (0)