diff mbox series

[XEN] xen: address MISRA C:2012 Rule 4.1

Message ID 378f18c287cfb65d25b42209c85645a2a10ff9b2.1689763253.git.nicola.vetrini@bugseng.com (mailing list archive)
State New, archived
Headers show
Series [XEN] xen: address MISRA C:2012 Rule 4.1 | expand

Commit Message

Nicola Vetrini July 19, 2023, 1:37 p.m. UTC
MISRA C:2012 Rule 4.1 has the following headline:
"Octal and hexadecimal escape sequences shall be terminated."

The string literals modified by this patch contain octal or
hexadecimal escape sequences that are neither terminated by the
end of the literal, nor by the beginning of another escape sequence.

Therefore, such unterminated sequences have been split into a
separate literal as a way to comply with the rule and preserve the
semantics of the code.

No functional changes.

Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
---
The choice whether to put a blank between the literals is up to
the maintainers' preference, I chose to do so to improve legibility.
---
 xen/arch/x86/hvm/hvm.c  | 2 +-
 xen/common/decompress.c | 4 ++--
 xen/common/xz/stream.h  | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

Comments

Stefano Stabellini July 20, 2023, 12:23 a.m. UTC | #1
On Wed, 19 Jul 2023, Nicola Vetrini wrote:
> MISRA C:2012 Rule 4.1 has the following headline:
> "Octal and hexadecimal escape sequences shall be terminated."
> 
> The string literals modified by this patch contain octal or
> hexadecimal escape sequences that are neither terminated by the
> end of the literal, nor by the beginning of another escape sequence.
> 
> Therefore, such unterminated sequences have been split into a
> separate literal as a way to comply with the rule and preserve the
> semantics of the code.
> 
> No functional changes.
> 
> Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>

Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>


> ---
> The choice whether to put a blank between the literals is up to
> the maintainers' preference, I chose to do so to improve legibility.
> ---
>  xen/arch/x86/hvm/hvm.c  | 2 +-
>  xen/common/decompress.c | 4 ++--
>  xen/common/xz/stream.h  | 2 +-
>  3 files changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c
> index 57363c2ae1..24ccf60d77 100644
> --- a/xen/arch/x86/hvm/hvm.c
> +++ b/xen/arch/x86/hvm/hvm.c
> @@ -3853,7 +3853,7 @@ void hvm_ud_intercept(struct cpu_user_regs *regs)
>                                          cs, &addr) &&
>               (hvm_copy_from_guest_linear(sig, addr, sizeof(sig),
>                                           walk, NULL) == HVMTRANS_okay) &&
> -             (memcmp(sig, "\xf\xbxen", sizeof(sig)) == 0) )
> +             (memcmp(sig, "\xf\xb" "xen", sizeof(sig)) == 0) )
>          {
>              regs->rip += sizeof(sig);
>              regs->eflags &= ~X86_EFLAGS_RF;
> diff --git a/xen/common/decompress.c b/xen/common/decompress.c
> index 989336983f..2c2c2ad877 100644
> --- a/xen/common/decompress.c
> +++ b/xen/common/decompress.c
> @@ -19,13 +19,13 @@ int __init decompress(void *inbuf, unsigned int len, void *outbuf)
>      if ( len >= 3 && !memcmp(inbuf, "\x42\x5a\x68", 3) )
>          return bunzip2(inbuf, len, NULL, NULL, outbuf, NULL, error);
>  
> -    if ( len >= 6 && !memcmp(inbuf, "\3757zXZ", 6) )
> +    if ( len >= 6 && !memcmp(inbuf, "\375" "7zXZ", 6) )
>          return unxz(inbuf, len, NULL, NULL, outbuf, NULL, error);
>  
>      if ( len >= 2 && !memcmp(inbuf, "\135\000", 2) )
>          return unlzma(inbuf, len, NULL, NULL, outbuf, NULL, error);
>  
> -    if ( len >= 5 && !memcmp(inbuf, "\x89LZO", 5) )
> +    if ( len >= 5 && !memcmp(inbuf, "\x89" "LZO", 5) )
>          return unlzo(inbuf, len, NULL, NULL, outbuf, NULL, error);
>  
>      if ( len >= 2 && !memcmp(inbuf, "\x02\x21", 2) )
> diff --git a/xen/common/xz/stream.h b/xen/common/xz/stream.h
> index d36d0fec64..8d9fbbe1b5 100644
> --- a/xen/common/xz/stream.h
> +++ b/xen/common/xz/stream.h
> @@ -18,7 +18,7 @@
>  
>  #define STREAM_HEADER_SIZE 12
>  
> -#define HEADER_MAGIC "\3757zXZ"
> +#define HEADER_MAGIC "\375" "7zXZ"
>  #define HEADER_MAGIC_SIZE 6
>  
>  #define FOOTER_MAGIC "YZ"
> -- 
> 2.34.1
>
Jan Beulich July 20, 2023, 3:25 p.m. UTC | #2
On 20.07.2023 02:23, Stefano Stabellini wrote:
> On Wed, 19 Jul 2023, Nicola Vetrini wrote:
>> MISRA C:2012 Rule 4.1 has the following headline:
>> "Octal and hexadecimal escape sequences shall be terminated."
>>
>> The string literals modified by this patch contain octal or
>> hexadecimal escape sequences that are neither terminated by the
>> end of the literal, nor by the beginning of another escape sequence.
>>
>> Therefore, such unterminated sequences have been split into a
>> separate literal as a way to comply with the rule and preserve the
>> semantics of the code.
>>
>> No functional changes.
>>
>> Signed-off-by: Nicola Vetrini <nicola.vetrini@bugseng.com>
> 
> Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>

In order to get this off the plate
Acked-by: Jan Beulich <jbeulich@suse.com>
albeit I'm not overly happy with ...

>> --- a/xen/arch/x86/hvm/hvm.c
>> +++ b/xen/arch/x86/hvm/hvm.c
>> @@ -3853,7 +3853,7 @@ void hvm_ud_intercept(struct cpu_user_regs *regs)
>>                                          cs, &addr) &&
>>               (hvm_copy_from_guest_linear(sig, addr, sizeof(sig),
>>                                           walk, NULL) == HVMTRANS_okay) &&
>> -             (memcmp(sig, "\xf\xbxen", sizeof(sig)) == 0) )
>> +             (memcmp(sig, "\xf\xb" "xen", sizeof(sig)) == 0) )

... this. Imo it should never have been a string literal here. But
I'm also not really up to making yet another alternative patch.

Jan
diff mbox series

Patch

diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c
index 57363c2ae1..24ccf60d77 100644
--- a/xen/arch/x86/hvm/hvm.c
+++ b/xen/arch/x86/hvm/hvm.c
@@ -3853,7 +3853,7 @@  void hvm_ud_intercept(struct cpu_user_regs *regs)
                                         cs, &addr) &&
              (hvm_copy_from_guest_linear(sig, addr, sizeof(sig),
                                          walk, NULL) == HVMTRANS_okay) &&
-             (memcmp(sig, "\xf\xbxen", sizeof(sig)) == 0) )
+             (memcmp(sig, "\xf\xb" "xen", sizeof(sig)) == 0) )
         {
             regs->rip += sizeof(sig);
             regs->eflags &= ~X86_EFLAGS_RF;
diff --git a/xen/common/decompress.c b/xen/common/decompress.c
index 989336983f..2c2c2ad877 100644
--- a/xen/common/decompress.c
+++ b/xen/common/decompress.c
@@ -19,13 +19,13 @@  int __init decompress(void *inbuf, unsigned int len, void *outbuf)
     if ( len >= 3 && !memcmp(inbuf, "\x42\x5a\x68", 3) )
         return bunzip2(inbuf, len, NULL, NULL, outbuf, NULL, error);
 
-    if ( len >= 6 && !memcmp(inbuf, "\3757zXZ", 6) )
+    if ( len >= 6 && !memcmp(inbuf, "\375" "7zXZ", 6) )
         return unxz(inbuf, len, NULL, NULL, outbuf, NULL, error);
 
     if ( len >= 2 && !memcmp(inbuf, "\135\000", 2) )
         return unlzma(inbuf, len, NULL, NULL, outbuf, NULL, error);
 
-    if ( len >= 5 && !memcmp(inbuf, "\x89LZO", 5) )
+    if ( len >= 5 && !memcmp(inbuf, "\x89" "LZO", 5) )
         return unlzo(inbuf, len, NULL, NULL, outbuf, NULL, error);
 
     if ( len >= 2 && !memcmp(inbuf, "\x02\x21", 2) )
diff --git a/xen/common/xz/stream.h b/xen/common/xz/stream.h
index d36d0fec64..8d9fbbe1b5 100644
--- a/xen/common/xz/stream.h
+++ b/xen/common/xz/stream.h
@@ -18,7 +18,7 @@ 
 
 #define STREAM_HEADER_SIZE 12
 
-#define HEADER_MAGIC "\3757zXZ"
+#define HEADER_MAGIC "\375" "7zXZ"
 #define HEADER_MAGIC_SIZE 6
 
 #define FOOTER_MAGIC "YZ"