chiark / gitweb /
util: introduce alloca0() and use it at a number of places
authorLennart Poettering <lennart@poettering.net>
Sun, 14 Apr 2013 15:43:59 +0000 (17:43 +0200)
committerLennart Poettering <lennart@poettering.net>
Sun, 14 Apr 2013 15:43:59 +0000 (17:43 +0200)
src/libsystemd-bus/bus-control.c
src/libsystemd-bus/bus-kernel.c
src/shared/util.h

index 5296029..e980bfc 100644 (file)
@@ -66,10 +66,9 @@ int sd_bus_request_name(sd_bus *bus, const char *name, int flags) {
                 size_t l;
 
                 l = strlen(name);
-                n = alloca(offsetof(struct kdbus_cmd_name, name) + l + 1);
+                n = alloca0(offsetof(struct kdbus_cmd_name, name) + l + 1);
                 n->size = offsetof(struct kdbus_cmd_name, name) + l + 1;
                 n->name_flags = flags;
-                n->id = 0;
                 memcpy(n->name, name, l+1);
 
 #ifdef HAVE_VALGRIND_MEMCHECK_H
@@ -121,10 +120,8 @@ int sd_bus_release_name(sd_bus *bus, const char *name) {
                 size_t l;
 
                 l = strlen(name);
-                n = alloca(offsetof(struct kdbus_cmd_name, name) + l + 1);
+                n = alloca0(offsetof(struct kdbus_cmd_name, name) + l + 1);
                 n->size = offsetof(struct kdbus_cmd_name, name) + l + 1;
-                n->name_flags = 0;
-                n->id = 0;
                 memcpy(n->name, name, l+1);
 
 #ifdef HAVE_VALGRIND_MEMCHECK_H
index b2d98c0..264c699 100644 (file)
@@ -474,8 +474,7 @@ int bus_kernel_create(const char *name, char **s) {
                 return -errno;
 
         l = strlen(name);
-        make = alloca(offsetof(struct kdbus_cmd_bus_make, name) + DECIMAL_STR_MAX(uid_t) + 1 + l + 1);
-        memset(make, 0, offsetof(struct kdbus_cmd_bus_make, name));
+        make = alloca0(offsetof(struct kdbus_cmd_bus_make, name) + DECIMAL_STR_MAX(uid_t) + 1 + l + 1);
         sprintf(make->name, "%lu-%s", (unsigned long) getuid(), name);
         make->size = offsetof(struct kdbus_cmd_bus_make, name) + strlen(make->name) + 1;
         make->flags = KDBUS_ACCESS_WORLD | KDBUS_POLICY_OPEN;
index ad97536..b33fdb5 100644 (file)
@@ -657,3 +657,11 @@ static inline unsigned decimal_str_max(unsigned x) {
 }
 
 int unlink_noerrno(const char *path);
+
+#define alloca0(n)                                                      \
+        ({                                                              \
+                char *__new;                                            \
+                size_t __len = n;                                       \
+                __new = alloca(__len);                                  \
+                (void *) memset(__new, 0, __len);                       \
+        })