]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core/dbus-cgroup: use %.*s instead of strndupa()
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 5 Nov 2019 17:15:46 +0000 (18:15 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 14 Nov 2019 17:41:54 +0000 (18:41 +0100)
src/core/dbus-cgroup.c

index 8e8e3dca4b3b9807218365c06ab1d3c739f5303f..591c5dd7f52f6c388a48ac7a06421255655cf778 100644 (file)
@@ -692,16 +692,14 @@ static int bus_cgroup_set_boolean(
                                                  "Value specified in %s is out of range", name); \
                                                                         \
                 if (!UNIT_WRITE_FLAGS_NOOP(flags)) {                    \
-                        const char *e;                                  \
-                                                                        \
                         *p = v;                                         \
                         unit_invalidate_cgroup(u, mask);                \
                                                                         \
-                        /* Chop off suffix */                           \
-                        assert_se(e = endswith(name, "Scale"));         \
-                        name = strndupa(name, e - name);                \
+                        /* Prepare to chop off suffix */                \
+                        assert_se(endswith(name, "Scale"));             \
                                                                         \
-                        unit_write_settingf(u, flags, name, "%s=%" PRIu32 "%%", name, \
+                        unit_write_settingf(u, flags, name, "%.*s=%" PRIu32 "%%", \
+                                            (int)(strlen(name) - strlen("Scale")), name, \
                                             (uint32_t) (DIV_ROUND_UP((uint64_t) raw * 100U, (uint64_t) UINT32_MAX))); \
                 }                                                       \
                                                                         \