From 0477ce4805de4f0f01e98b04ed9acf4168ed805e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Thomas=20Wei=C3=9Fschuh?= Date: Tue, 19 Mar 2024 22:49:31 +0100 Subject: [PATCH] lscpu: restructure op-mode printing MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The existing logic can confuse ASAN. Restructure it so it is shorter and easer to understand for humans. Signed-off-by: Thomas Weißschuh --- sys-utils/lscpu.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/sys-utils/lscpu.c b/sys-utils/lscpu.c index a65ccad5e4..c073fc0dc4 100644 --- a/sys-utils/lscpu.c +++ b/sys-utils/lscpu.c @@ -990,18 +990,16 @@ static void print_summary(struct lscpu_cxt *cxt) /* Section: architecture */ sec = add_summary_s(tb, NULL, _("Architecture:"), cxt->arch->name); if (cxt->arch->bit32 || cxt->arch->bit64) { - char buf[32], *p = buf; + const char *p; - if (cxt->arch->bit32) { - strcpy(p, "32-bit, "); - p += 8; - } - if (cxt->arch->bit64) { - strcpy(p, "64-bit, "); - p += 8; - } - *(p - 2) = '\0'; - add_summary_s(tb, sec, _("CPU op-mode(s):"), buf); + if (cxt->arch->bit32 && cxt->arch->bit64) + p = "32-bit, 64-bit"; + else if (cxt->arch->bit32) + p = "32-bit"; + else + p = "64-bit"; + + add_summary_s(tb, sec, _("CPU op-mode(s):"), p); } if (ct && ct->addrsz) add_summary_s(tb, sec, _("Address sizes:"), ct->addrsz); -- 2.47.2