On 18/04/2024 12:06 pm, Jan Beulich wrote: > On 17.04.2024 09:14, Roger Pau Monné wrote: >> On Tue, Apr 16, 2024 at 04:52:51PM +0100, Andrew Cooper wrote: >>> --- a/xen/common/efi/pe.c >>> +++ b/xen/common/efi/pe.c >>> @@ -111,7 +111,8 @@ const void *__init pe_find_section(const void *image, >>> const UINTN image_size, >>> UINTN offset, i; >>> >>> if ( image_size < sizeof(*dos) || >>> - memcmp(dos->Magic, "MZ", 2) != 0 ) >>> + dos->Magic[0] != 'M' || >>> + dos->Magic[1] != 'Z' ) >> For this one you could likely use strncmp()? > strncmp() against UINT8[2] wouldn't be liked by the compiler, I guess.
Indeed. And this MISRA rule is very much "you are mixing string and non-string types. Don't do that." This is a very rare patten, where we are looking for a binary marker than just happens to also make sense when expressed as an ASCII string. Although the MISRA complaint does raise a good point. The memcmp() form would malfunction on any system with CHAR_BIT != 8, in a way that the {u,}int8_t-at-a-time form wouldn't. ~Andrew