From: Jan Beulich <jbeulich@suse.com>
To: Andrew Cooper <andrew.cooper3@citrix.com>,
Nicola Vetrini <nicola.vetrini@bugseng.com>
Cc: sstabellini@kernel.org, michal.orzel@amd.com,
xenia.ragiadakou@amd.com, ayan.kumar.halder@amd.com,
consulting@bugseng.com, roger.pau@citrix.com,
George Dunlap <george.dunlap@citrix.com>,
Julien Grall <julien@xen.org>, Wei Liu <wl@xen.org>,
xen-devel@lists.xenproject.org
Subject: Re: [RFC PATCH 1/4] xen/vsprintf: replace backwards jump with loop
Date: Tue, 21 Nov 2023 14:52:01 +0100 [thread overview]
Message-ID: <d5bfc0d7-148e-4d49-85a0-e23387635daf@suse.com> (raw)
In-Reply-To: <8d9c85db-5afd-4299-8f05-e74628c1f67b@citrix.com>
On 07.11.2023 12:36, Andrew Cooper wrote:
> On 07/11/2023 10:33 am, Nicola Vetrini wrote:
>> 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 <nicola.vetrini@bugseng.com>
>> ---
>> 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;
>> + }
>
> I'm firmly against this change. It takes a simple and clear piece of
> code and replaces it with something harder to follow because you have to
> look elsewhere to figure how the variable works.
While I don't really like that change either, I also don't like uses of
goto (at some point we said using it for error handling is okay, but
the case here is clearly not in that category). So at least for
consideration, how about getting away without a new variable:
for ( ; ; )
{
++fmt; /* this also skips the first '%' */
switch ( *fmt )
{
case '-': flags |= LEFT; continue;
case '+': flags |= PLUS; continue;
case ' ': flags |= SPACE; continue;
case '#': flags |= SPECIAL; continue;
case '0': flags |= ZEROPAD; continue;
}
break;
}
Jan
next prev parent reply other threads:[~2023-11-21 13:52 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-07 10:33 [RFC PATCH 0/4] address MISRA C:2012 Rule 15.2 Nicola Vetrini
2023-11-07 10:33 ` [RFC PATCH 1/4] xen/vsprintf: replace backwards jump with loop Nicola Vetrini
2023-11-07 11:36 ` Andrew Cooper
2023-11-21 13:52 ` Jan Beulich [this message]
2023-11-07 10:33 ` [RFC PATCH 2/4] x86/dom0: make goto jump forward Nicola Vetrini
2023-11-21 13:57 ` Jan Beulich
2023-11-07 10:33 ` [RFC PATCH 3/4] xen/arm: GICv3: address MISRA C:2012 Rule 15.2 Nicola Vetrini
2023-11-07 12:34 ` Julien Grall
2023-11-07 10:33 ` [RFC PATCH 4/4] automation/eclair: add deviation for certain backwards goto Nicola Vetrini
2023-11-07 12:44 ` Julien Grall
2023-11-07 14:45 ` Nicola Vetrini
2023-11-07 17:35 ` Julien Grall
2023-11-08 10:10 ` Nicola Vetrini
2023-11-07 10:52 ` [RFC PATCH 0/4] address MISRA C:2012 Rule 15.2 Jan Beulich
2023-11-07 11:10 ` Nicola Vetrini
2023-11-21 14:41 ` Nicola Vetrini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d5bfc0d7-148e-4d49-85a0-e23387635daf@suse.com \
--to=jbeulich@suse.com \
--cc=andrew.cooper3@citrix.com \
--cc=ayan.kumar.halder@amd.com \
--cc=consulting@bugseng.com \
--cc=george.dunlap@citrix.com \
--cc=julien@xen.org \
--cc=michal.orzel@amd.com \
--cc=nicola.vetrini@bugseng.com \
--cc=roger.pau@citrix.com \
--cc=sstabellini@kernel.org \
--cc=wl@xen.org \
--cc=xen-devel@lists.xenproject.org \
--cc=xenia.ragiadakou@amd.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.