From patchwork Tue Nov 7 10:33:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicola Vetrini X-Patchwork-Id: 13448456 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E3B1EC4167D for ; Tue, 7 Nov 2023 10:34:03 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.628727.980503 (Exim 4.92) (envelope-from ) id 1r0JP9-00050n-Gn; Tue, 07 Nov 2023 10:33:55 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 628727.980503; Tue, 07 Nov 2023 10:33:55 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r0JP9-00050g-Dg; Tue, 07 Nov 2023 10:33:55 +0000 Received: by outflank-mailman (input) for mailman id 628727; Tue, 07 Nov 2023 10:33:53 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1r0JP7-0004jI-M9 for xen-devel@lists.xenproject.org; Tue, 07 Nov 2023 10:33:53 +0000 Received: from support.bugseng.com (mail.bugseng.com [162.55.131.47]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 24894e44-7d59-11ee-9b0e-b553b5be7939; Tue, 07 Nov 2023 11:33:51 +0100 (CET) Received: from nico.bugseng.com (unknown [147.123.100.131]) by support.bugseng.com (Postfix) with ESMTPSA id 18D2C4EE0C88; Tue, 7 Nov 2023 11:33:49 +0100 (CET) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 24894e44-7d59-11ee-9b0e-b553b5be7939 From: Nicola Vetrini To: xen-devel@lists.xenproject.org Cc: sstabellini@kernel.org, michal.orzel@amd.com, xenia.ragiadakou@amd.com, ayan.kumar.halder@amd.com, consulting@bugseng.com, jbeulich@suse.com, andrew.cooper3@citrix.com, roger.pau@citrix.com, Nicola Vetrini , George Dunlap , Julien Grall , Wei Liu Subject: [RFC PATCH 1/4] xen/vsprintf: replace backwards jump with loop Date: Tue, 7 Nov 2023 11:33:42 +0100 Message-Id: <9fbc2bcfa1ee019a8ac1cd1a3d29c38b59b8edff.1699295113.git.nicola.vetrini@bugseng.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: MIME-Version: 1.0 The backwards goto in the vsnprintf function can be replaced with a loop, thereby fixing a violation of MISRA C:2012 Rule 15.2. Signed-off-by: Nicola Vetrini --- xen/common/vsprintf.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/xen/common/vsprintf.c b/xen/common/vsprintf.c index c49631c0a4d8..603bae44177a 100644 --- a/xen/common/vsprintf.c +++ b/xen/common/vsprintf.c @@ -495,6 +495,8 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args) } for (; *fmt ; ++fmt) { + bool repeat = true; + if (*fmt != '%') { if (str < end) *str = *fmt; @@ -504,14 +506,16 @@ int vsnprintf(char *buf, size_t size, const char *fmt, va_list args) /* process flags */ flags = 0; - repeat: - ++fmt; /* this also skips first '%' */ - switch (*fmt) { - case '-': flags |= LEFT; goto repeat; - case '+': flags |= PLUS; goto repeat; - case ' ': flags |= SPACE; goto repeat; - case '#': flags |= SPECIAL; goto repeat; - case '0': flags |= ZEROPAD; goto repeat; + while ( repeat ) { + ++fmt; /* this also skips the first '%' */ + switch (*fmt) { + case '-': flags |= LEFT; break; + case '+': flags |= PLUS; break; + case ' ': flags |= SPACE; break; + case '#': flags |= SPECIAL; break; + case '0': flags |= ZEROPAD; break; + default: repeat = false; break; + } } /* get field width */