summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@openwrt.org>2012-12-31 16:36:01 +0100
committerFelix Fietkau <nbd@openwrt.org>2012-12-31 16:36:16 +0100
commitfabdd4fc5c7354e897f91e96e734f584776736c7 (patch)
tree26202e94439e57af2f9e96c949d52f2046c6d6a3
parent28735bd31f043d39f024d53e48ce767b95e5d70e (diff)
downloadnetifd-fabdd4fc5c7354e897f91e96e734f584776736c7.tar.gz
use calloc_a for interface error allocations
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
-rw-r--r--interface.c32
-rw-r--r--netifd.h1
2 files changed, 9 insertions, 24 deletions
diff --git a/interface.c b/interface.c
index 77654fe..352c734 100644
--- a/interface.c
+++ b/interface.c
@@ -79,8 +79,7 @@ void interface_add_error(struct interface *iface, const char *subsystem,
struct interface_error *error;
int i, len = 0;
int *datalen = NULL;
- char *dest;
- int subsystem_len = 0, code_len = 0;
+ char *dest, *d_subsys, *d_code;
if (n_data) {
len = n_data * sizeof(char *);
@@ -91,17 +90,9 @@ void interface_add_error(struct interface *iface, const char *subsystem,
}
}
- if (subsystem) {
- subsystem_len = strlen(subsystem) + 1;
- len += subsystem_len;
- }
-
- if (code) {
- code_len = strlen(code) + 1;
- len += code_len;
- }
-
- error = calloc(1, sizeof(*error) + sizeof(char *) + len);
+ error = calloc_a(sizeof(*error) + sizeof(char *) + len,
+ &d_subsys, subsystem ? strlen(subsystem) + 1 : 0,
+ &d_code, code ? strlen(code) + 1 : 0);
if (!error)
return;
@@ -115,18 +106,11 @@ void interface_add_error(struct interface *iface, const char *subsystem,
}
error->data[n_data++] = NULL;
- dest = (char *) &error->data[n_data];
- if (subsystem) {
- error->subsystem = dest;
- strcpy(dest, subsystem);
- dest += subsystem_len;
- }
+ if (subsystem)
+ error->subsystem = strcpy(d_subsys, subsystem);
- if (code) {
- error->code = dest;
- strcpy(dest, code);
- dest += code_len;
- }
+ if (code)
+ error->code = strcpy(d_code, code);
}
static void
diff --git a/netifd.h b/netifd.h
index aa955ef..befa2cc 100644
--- a/netifd.h
+++ b/netifd.h
@@ -22,6 +22,7 @@
#include <libubox/uloop.h>
#include <libubox/ustream.h>
+#include <libubox/utils.h>
#include <libubus.h>