mirror of
https://github.com/openwrt/openwrt.git
synced 2026-07-20 16:11:59 +04:00
nvram: use flex array
Clarifies that the struct needs to be over allocated. Signed-off-by: Rosen Penev <rosenp@gmail.com> Link: https://github.com/openwrt/openwrt/pull/22370 Signed-off-by: Jonas Jelonek <jelonek.jonas@gmail.com>
This commit is contained in:
committed by
Jonas Jelonek
parent
51a018ee49
commit
55d146432f
@@ -77,7 +77,6 @@ static nvram_tuple_t * _nvram_realloc( nvram_handle_t *h, nvram_tuple_t *t,
|
||||
return NULL;
|
||||
|
||||
/* Copy name */
|
||||
t->name = (char *) &t[1];
|
||||
strcpy(t->name, name);
|
||||
|
||||
t->value = NULL;
|
||||
@@ -242,9 +241,9 @@ nvram_tuple_t * nvram_getall(nvram_handle_t *h)
|
||||
|
||||
for (i = 0; i < NVRAM_ARRAYSIZE(h->nvram_hash); i++) {
|
||||
for (t = h->nvram_hash[i]; t; t = t->next) {
|
||||
if( (x = (nvram_tuple_t *) malloc(sizeof(nvram_tuple_t))) != NULL )
|
||||
if( (x = malloc(sizeof(*x) + strlen(t->name) + 1)) != NULL )
|
||||
{
|
||||
x->name = t->name;
|
||||
strcpy(x->name, t->name);
|
||||
x->value = t->value;
|
||||
x->next = l;
|
||||
l = x;
|
||||
|
||||
@@ -38,9 +38,9 @@ struct nvram_header {
|
||||
} __attribute__((__packed__));
|
||||
|
||||
struct nvram_tuple {
|
||||
char *name;
|
||||
char *value;
|
||||
struct nvram_tuple *next;
|
||||
char name[];
|
||||
};
|
||||
|
||||
struct nvram_handle {
|
||||
|
||||
Reference in New Issue
Block a user