From e617e2ccd790fda92efadcb917ba90de9f832022 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Tue, 5 Nov 2019 18:15:46 +0100 Subject: [PATCH] core/dbus-cgroup: use %.*s instead of strndupa() --- src/core/dbus-cgroup.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/core/dbus-cgroup.c b/src/core/dbus-cgroup.c index 8e8e3dca4b3..591c5dd7f52 100644 --- a/src/core/dbus-cgroup.c +++ b/src/core/dbus-cgroup.c @@ -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))); \ } \ \