[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [RFC PATCH 1/4] xen/vsprintf: replace backwards jump with loop
- To: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Nicola Vetrini <nicola.vetrini@xxxxxxxxxxx>
- From: Jan Beulich <jbeulich@xxxxxxxx>
- Date: Tue, 21 Nov 2023 14:52:01 +0100
- Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=5F5YCi1yVZWlpas+ceLImFf3IaH4ucz+ZF73lPmOuXw=; b=LwMx5fFD55/mNahyGhgtzzV4nnGt72rvA8zZh+Zn12eyOqvU9x1BIEqiQw+oajdO//ul5iHpxFTdCEZXdMQTp6vtndWdYUsZvYHNxTBEwvPbCKP6rgJbvGUo5KcxQ1WLRqEESoEdpjNumNwGlzUHyTPVWfVidvKkpTkmQRg6qiRoxGvCf3usm0D2ejFJgboeMnCfSsZ6fRILL9HFx+bekCqXiLjEU/otjZ8BvZuxpUzDGKVYL/1LeO9BhE9b1+udm7LsmmI/tF8mtw6enrHBPvCfAYtAGCXI3SCtn5OdoIrrwYLxUyl90w0xENznGDOOaLbYzQoULA6lI0ir/Xu0Eg==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EprfpCcc/fX3rp+nEuxrqR79kAW460ykmatKS5N7k2A77QhH66mBA3Fptc/JL9WDacqvi32w8kMY3E/yx1UTXOEjcuO98lqlpLUYneMsnE1UUrZ3rhzR0fOgKnDJX/rYeMEmdHAil9jOx/WDjGl3tUmYzUEtHYql+2AhKgL7jAe3S8wNfMTru/FjF48RlOFcpCQYnFiX+1cv+BAlT5DWNSW3q5AJnq/f2X9hbevQBLivi+t7ruxs5ArOOXUXYxF7ItuOpFtLVg9MJYt9PpCPxqFOO4fV6q47CdfQwrkxgc4gWK3Q99KUV+8xlods8XfAptP513DI3dct8qF7Qeyl2w==
- Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
- Autocrypt: addr=jbeulich@xxxxxxxx; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i1cqqSDtVlt+AOVBJBACrZcnHAUSuCXBPy0jOlBhxPqRWv6ND4c9PH1xjQ3NP nxJuMBS8rnNg22uyfAgmBKNLpLgAGVRMZGaGoJObGf72s6TeIqKJo/LtggAS9qAUiuKVnygo 3wjfkS9A3DRO+SpU7JqWdsveeIQyeyEJ/8PTowmSQLakF+3fote9ybzd880fSmFuIEJldWxp Y2ggPGpiZXVsaWNoQHN1c2UuY29tPsJgBBMRAgAgBQJZN5xEAhsDBgsJCAcDAgQVAggDBBYC AwECHgECF4AACgkQoDSui/t3IH4J+wCfQ5jHdEjCRHj23O/5ttg9r9OIruwAn3103WUITZee e7Sbg12UgcQ5lv7SzsFNBFk3nEQQCACCuTjCjFOUdi5Nm244F+78kLghRcin/awv+IrTcIWF hUpSs1Y91iQQ7KItirz5uwCPlwejSJDQJLIS+QtJHaXDXeV6NI0Uef1hP20+y8qydDiVkv6l IreXjTb7DvksRgJNvCkWtYnlS3mYvQ9NzS9PhyALWbXnH6sIJd2O9lKS1Mrfq+y0IXCP10eS FFGg+Av3IQeFatkJAyju0PPthyTqxSI4lZYuJVPknzgaeuJv/2NccrPvmeDg6Coe7ZIeQ8Yj t0ARxu2xytAkkLCel1Lz1WLmwLstV30g80nkgZf/wr+/BXJW/oIvRlonUkxv+IbBM3dX2OV8 AmRv1ySWPTP7AAMFB/9PQK/VtlNUJvg8GXj9ootzrteGfVZVVT4XBJkfwBcpC/XcPzldjv+3 HYudvpdNK3lLujXeA5fLOH+Z/G9WBc5pFVSMocI71I8bT8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL
- Cc: sstabellini@xxxxxxxxxx, michal.orzel@xxxxxxx, xenia.ragiadakou@xxxxxxx, ayan.kumar.halder@xxxxxxx, consulting@xxxxxxxxxxx, roger.pau@xxxxxxxxxx, George Dunlap <george.dunlap@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Wei Liu <wl@xxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
- Delivery-date: Tue, 21 Nov 2023 13:52:29 +0000
- List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
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@xxxxxxxxxxx>
>> ---
>> 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
|