[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [XEN PATCH v3] xen/string: address violations of MISRA C:2012 Rules 8.2 and 8.3


  • To: Federico Serafini <federico.serafini@xxxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Wed, 8 Nov 2023 09:07:48 +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=8QaBxUfnatMweMqqI2yFQaKMByKzbLYi5OTYIF3vqcA=; b=IOjVrFNiYBsdn1VxWcVJpiR4GO8DJFGcT0Jhki/JbjqJtkWa7+6SpIKo3eywrucIisnck/bIOQAPGE4C1eoLtiZYbaD/wULQHfF8YMQ9C1s4eGX6rhO6D2adgpBBoBztP+lcHM5nfPzVD3YoT6s20Z2E+4XleZOrtOjh+9nyfY8sBCU+Wnxzq13zjlg/QtJ3xrOIzguPAkSkZaYRUy9VrXCmKpmlwcvTWEWGt0k4uzk47oiTfDFShT1+xMtyusVbnmjZPmQ/KONwlLB7FqkpKz1kCoSRp50pLX1/wp10zGyRtPgVSzaQ1QUpJfssAy+2GH7Kl2sLcvzReuVcPH6sjA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nJ2g83SPAB71cwTKfJgO6oxojG6is+1SXoYmn+oITmSuPI1C7ZWvbduYpAv1Cd8iA/cuBBAvAs+KWMRyYIOFfJjihtp8CwGJ+u7nstF6/CcOCTNnWsjx9idZCaqybzV9LSoaH5HZ8IFdqpbT8sfbOeUOdu4nPDMcF2Q7rklrT9RgWoOYAenAp7HeoBrE1XfOPfLb87TGtQTZecBmrQAg4intKOBY1DawGPHMsRuBiHGbDHK4mqrsyVcc2Z8+Sc/XhEnD43GCUT6oJonf0n7YUcqQ5BfWYjlpIxedZ2dpKiDM1UN/PdNd5UjlVDj3dL5nGdC902fY4P7zdAbBoeJw2Q==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: consulting@xxxxxxxxxxx, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • Delivery-date: Wed, 08 Nov 2023 08:08:14 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 07.11.2023 16:18, Federico Serafini wrote:
> Add missing parameter names and make function declarations and
> definitions consistent.
> Mismatches between parameter names "count" and "n" are resolved
> in favor of "n", being the same name used by the C standard.

I'm afraid this wasn't done consistently:

> --- a/xen/include/xen/string.h
> +++ b/xen/include/xen/string.h
> @@ -12,27 +12,27 @@
>  #define strncpy __xen_has_no_strncpy__
>  #define strncat __xen_has_no_strncat__
>  
> -size_t strlcpy(char *, const char *, size_t);
> -size_t strlcat(char *, const char *, size_t);
> -int strcmp(const char *, const char *);
> -int strncmp(const char *, const char *, size_t);
> -int strcasecmp(const char *, const char *);
> -int strncasecmp(const char *, const char *, size_t);
> -char *strchr(const char *, int);
> -char *strrchr(const char *, int);
> -char *strstr(const char *, const char *);
> -size_t strlen(const char *);
> -size_t strnlen(const char *, size_t);
> -char *strpbrk(const char *, const char *);
> -char *strsep(char **, const char *);
> -size_t strspn(const char *, const char *);
> -
> -void *memset(void *, int, size_t);
> -void *memcpy(void *, const void *, size_t);
> -void *memmove(void *, const void *, size_t);
> -int memcmp(const void *, const void *, size_t);
> -void *memchr(const void *, int, size_t);
> -void *memchr_inv(const void *, int, size_t);
> +size_t strlcpy(char *dest, const char *src, size_t size);
> +size_t strlcat(char *dest, const char *src, size_t size);
> +int strcmp(const char *cs, const char *ct);
> +int strncmp(const char *cs, const char *ct, size_t count);

There's still "count" here and ...

> +int strcasecmp(const char *s1, const char *s2);
> +int strncasecmp(const char *s1, const char *s2, size_t len);
> +char *strchr(const char *s, int c);
> +char *strrchr(const char *s, int c);
> +char *strstr(const char *s1, const char *s2);
> +size_t strlen(const char *s);
> +size_t strnlen(const char *s, size_t count);
> +char *strpbrk(const char *cs,const char *ct);
> +char *strsep(char **s, const char *ct);
> +size_t strspn(const char *s, const char *accept);
> +
> +void *memset(void *s, int c, size_t n);
> +void *memcpy(void *dest, const void *src, size_t n);
> +void *memmove(void *dest, const void *src, size_t n);
> +int memcmp(const void *cs, const void *ct, size_t count);

... here (not counting functions which aren't part of the C standard).

Otoh I'm unsure I understand that part of the description correctly:
There was no disagreement for any of ...

> --- a/xen/lib/memcpy.c
> +++ b/xen/lib/memcpy.c
> @@ -8,16 +8,16 @@
>   * memcpy - Copy one area of memory to another
>   * @dest: Where to copy to
>   * @src: Where to copy from
> - * @count: The size of the area.
> + * @n: The size of the area.
>   *
>   * You should not use this function to access IO space, use memcpy_toio()
>   * or memcpy_fromio() instead.
>   */
> -void *(memcpy)(void *dest, const void *src, size_t count)
> +void *(memcpy)(void *dest, const void *src, size_t n)
>  {
>       char *tmp = (char *) dest, *s = (char *) src;
>  
> -     while (count--)
> +     while (n--)
>               *tmp++ = *s++;
>  
>       return dest;
> --- a/xen/lib/memmove.c
> +++ b/xen/lib/memmove.c
> @@ -8,23 +8,23 @@
>   * memmove - Copy one area of memory to another
>   * @dest: Where to copy to
>   * @src: Where to copy from
> - * @count: The size of the area.
> + * @n: The size of the area.
>   *
>   * Unlike memcpy(), memmove() copes with overlapping areas.
>   */
> -void *(memmove)(void *dest, const void *src, size_t count)
> +void *(memmove)(void *dest, const void *src, size_t n)
>  {
>       char *tmp, *s;
>  
>       if (dest <= src) {
>               tmp = (char *) dest;
>               s = (char *) src;
> -             while (count--)
> +             while (n--)
>                       *tmp++ = *s++;
>       } else {
> -             tmp = (char *) dest + count;
> -             s = (char *) src + count;
> -             while (count--)
> +             tmp = (char *) dest + n;
> +             s = (char *) src + n;
> +             while (n--)
>                       *--tmp = *--s;
>       }
>  
> --- a/xen/lib/memset.c
> +++ b/xen/lib/memset.c
> @@ -8,15 +8,15 @@
>   * memset - Fill a region of memory with the given value
>   * @s: Pointer to the start of the area.
>   * @c: The byte to fill the area with
> - * @count: The size of the area.
> + * @n: The size of the area.
>   *
>   * Do not use memset() to access IO space, use memset_io() instead.
>   */
> -void *(memset)(void *s, int c, size_t count)
> +void *(memset)(void *s, int c, size_t n)
>  {
>       char *xs = (char *) s;
>  
> -     while (count--)
> +     while (n--)
>               *xs++ = c;
>  
>       return s;

... these, seeing that the declarations simply didn't have any parameter
names at all.

Jan



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.