[PATCH] lib: make memchr_inv() compliant with Misra rule 11.8

Jan Beulich posted 1 patch 1 day, 19 hours ago
[PATCH] lib: make memchr_inv() compliant with Misra rule 11.8
Posted by Jan Beulich 1 day, 19 hours ago
Neither the sole present caller nor the two ones pending (in the AMX/ACE
series on x86) require the casting away of constness.

Signed-off-by: Jan Beulich <jbeulich@suse.com>

--- a/xen/include/xen/string.h
+++ b/xen/include/xen/string.h
@@ -33,7 +33,7 @@ void *memcpy(void *dest, const void *src
 void *memmove(void *dest, const void *src, size_t n);
 int memcmp(const void *cs, const void *ct, size_t count);
 void *memchr(const void *s, int c, size_t n);
-void *memchr_inv(const void *s, int c, size_t n);
+const void *memchr_inv(const void *s, int c, size_t n);
 
 #include <asm/string.h>
 
--- a/xen/lib/memchr_inv.c
+++ b/xen/lib/memchr_inv.c
@@ -13,13 +13,13 @@
  * returns the address of the first occurrence of a character other than @c,
  * or %NULL if the whole buffer contains just @c.
  */
-void *memchr_inv(const void *s, int c, size_t n)
+const void *memchr_inv(const void *s, int c, size_t n)
 {
 	const unsigned char *p = s;
 
 	while (n--)
 		if ((unsigned char)c != *p++)
-			return (void *)(p - 1);
+			return p - 1;
 
 	return NULL;
 }
Re: [PATCH] lib: make memchr_inv() compliant with Misra rule 11.8
Posted by Dmytro Prokopchuk 1 day, 17 hours ago

On 11/3/26 13:24, Jan Beulich wrote:
> Neither the sole present caller nor the two ones pending (in the AMX/ACE
> series on x86) require the casting away of constness.
> 
> Signed-off-by: Jan Beulich <jbeulich@suse.com>
> 
> --- a/xen/include/xen/string.h
> +++ b/xen/include/xen/string.h
> @@ -33,7 +33,7 @@ void *memcpy(void *dest, const void *src
>   void *memmove(void *dest, const void *src, size_t n);
>   int memcmp(const void *cs, const void *ct, size_t count);
>   void *memchr(const void *s, int c, size_t n);
> -void *memchr_inv(const void *s, int c, size_t n);
> +const void *memchr_inv(const void *s, int c, size_t n);
>   
>   #include <asm/string.h>
>   
> --- a/xen/lib/memchr_inv.c
> +++ b/xen/lib/memchr_inv.c
> @@ -13,13 +13,13 @@
>    * returns the address of the first occurrence of a character other than @c,
>    * or %NULL if the whole buffer contains just @c.
>    */
> -void *memchr_inv(const void *s, int c, size_t n)
> +const void *memchr_inv(const void *s, int c, size_t n)
>   {
>   	const unsigned char *p = s;
>   
>   	while (n--)
>   		if ((unsigned char)c != *p++)
> -			return (void *)(p - 1);
> +			return p - 1;
>   
>   	return NULL;
>   }

Reviewed-by: Dmytro Prokopchuk <dmytro_prokopchuk1@epam.com>

BR, Dmytro.