[PATCH] docs/misra: adds Mandatory rules

Stefano Stabellini posted 1 patch 12 months ago
Patches applied successfully (tree, apply log)
git fetch https://gitlab.com/xen-project/patchew/xen tags/patchew/20230511232237.3720769-1-sstabellini@kernel.org
docs/misra/rules.rst | 62 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 62 insertions(+)
[PATCH] docs/misra: adds Mandatory rules
Posted by Stefano Stabellini 12 months ago
From: Stefano Stabellini <stefano.stabellini@amd.com>

Add the Mandatory rules agreed by the MISRA C working group to
docs/misra/rules.rst.

Signed-off-by: Stefano Stabellini <stefano.stabellini@amd.com>
---
 docs/misra/rules.rst | 62 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 62 insertions(+)

diff --git a/docs/misra/rules.rst b/docs/misra/rules.rst
index 83f01462f7..d5a6ee8cb6 100644
--- a/docs/misra/rules.rst
+++ b/docs/misra/rules.rst
@@ -204,6 +204,12 @@ existing codebase are work-in-progress.
        braces
      -
 
+   * - `Rule 12.5 <https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/-/blob/master/R_12_05.c>`_
+     - Mandatory
+     - The sizeof operator shall not have an operand which is a function
+       parameter declared as "array of type"
+     -
+
    * - `Rule 13.6 <https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/-/blob/master/R_13_06.c>`_
      - Mandatory
      - The operand of the sizeof operator shall not contain any
@@ -274,3 +280,59 @@ existing codebase are work-in-progress.
        in the same file as the #if #ifdef or #ifndef directive to which
        they are related
      -
+
+   * - `Rule 21.13 <https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/-/blob/master/R_21_13.c>`_
+     - Mandatory
+     - Any value passed to a function in <ctype.h> shall be representable as an
+       unsigned char or be the value EOF
+     -
+
+   * - `Rule 21.17 <https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/-/blob/master/R_21_17.c>`_
+     - Mandatory
+     - Use of the string handling functions from <string.h> shall not result in
+       accesses beyond the bounds of the objects referenced by their pointer
+       parameters
+     -
+
+   * - `Rule 21.18 <https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/-/blob/master/R_21_18.c>`_
+     - Mandatory
+     - The size_t argument passed to any function in <string.h> shall have an
+       appropriate value
+     -
+
+   * - `Rule 21.19 <https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/-/blob/master/R_21_19.c>`_
+     - Mandatory
+     - The pointers returned by the Standard Library functions localeconv,
+       getenv, setlocale or, strerror shall only be used as if they have
+       pointer to const-qualified type
+     -
+
+   * - `Rule 21.20 <https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/-/blob/master/R_21_20.c>`_
+     - Mandatory
+     - The pointer returned by the Standard Library functions asctime ctime
+       gmtime localtime localeconv getenv setlocale or strerror shall not be
+       used following a subsequent call to the same function
+     -
+
+   * - `Rule 22.2 <https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/-/blob/master/R_22_02.c>`_
+     - Mandatory
+     - A block of memory shall only be freed if it was allocated by means of a
+       Standard Library function
+     -
+
+   * - `Rule 22.4 <https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/-/blob/master/R_22_04.c>`_
+     - Mandatory
+     - There shall be no attempt to write to a stream which has been opened as
+       read-only
+     -
+
+   * - `Rule 22.5 <https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/-/blob/master/R_22_05.c>`_
+     - Mandatory
+     - A pointer to a FILE object shall not be dereferenced
+     -
+
+   * - `Rule 22.6 <https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/-/blob/master/R_22_06.c>`_
+     - Mandatory
+     - The value of a pointer to a FILE shall not be used after the associated
+       stream has been closed
+     -
-- 
2.25.1
Re: [PATCH] docs/misra: adds Mandatory rules
Posted by Bertrand Marquis 11 months, 2 weeks ago
Hi Stefano,


> On 12 May 2023, at 01:22, Stefano Stabellini <sstabellini@kernel.org> wrote:
> 
> From: Stefano Stabellini <stefano.stabellini@amd.com>
> 
> Add the Mandatory rules agreed by the MISRA C working group to
> docs/misra/rules.rst.
> 
> Signed-off-by: Stefano Stabellini <stefano.stabellini@amd.com>

Acked-by: Bertrand Marquis <bertrand.marquis@arm.com>

Cheers
Bertrand

> ---
> docs/misra/rules.rst | 62 ++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 62 insertions(+)
> 
> diff --git a/docs/misra/rules.rst b/docs/misra/rules.rst
> index 83f01462f7..d5a6ee8cb6 100644
> --- a/docs/misra/rules.rst
> +++ b/docs/misra/rules.rst
> @@ -204,6 +204,12 @@ existing codebase are work-in-progress.
>        braces
>      -
> 
> +   * - `Rule 12.5 <https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/-/blob/master/R_12_05.c>`_
> +     - Mandatory
> +     - The sizeof operator shall not have an operand which is a function
> +       parameter declared as "array of type"
> +     -
> +
>    * - `Rule 13.6 <https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/-/blob/master/R_13_06.c>`_
>      - Mandatory
>      - The operand of the sizeof operator shall not contain any
> @@ -274,3 +280,59 @@ existing codebase are work-in-progress.
>        in the same file as the #if #ifdef or #ifndef directive to which
>        they are related
>      -
> +
> +   * - `Rule 21.13 <https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/-/blob/master/R_21_13.c>`_
> +     - Mandatory
> +     - Any value passed to a function in <ctype.h> shall be representable as an
> +       unsigned char or be the value EOF
> +     -
> +
> +   * - `Rule 21.17 <https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/-/blob/master/R_21_17.c>`_
> +     - Mandatory
> +     - Use of the string handling functions from <string.h> shall not result in
> +       accesses beyond the bounds of the objects referenced by their pointer
> +       parameters
> +     -
> +
> +   * - `Rule 21.18 <https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/-/blob/master/R_21_18.c>`_
> +     - Mandatory
> +     - The size_t argument passed to any function in <string.h> shall have an
> +       appropriate value
> +     -
> +
> +   * - `Rule 21.19 <https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/-/blob/master/R_21_19.c>`_
> +     - Mandatory
> +     - The pointers returned by the Standard Library functions localeconv,
> +       getenv, setlocale or, strerror shall only be used as if they have
> +       pointer to const-qualified type
> +     -
> +
> +   * - `Rule 21.20 <https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/-/blob/master/R_21_20.c>`_
> +     - Mandatory
> +     - The pointer returned by the Standard Library functions asctime ctime
> +       gmtime localtime localeconv getenv setlocale or strerror shall not be
> +       used following a subsequent call to the same function
> +     -
> +
> +   * - `Rule 22.2 <https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/-/blob/master/R_22_02.c>`_
> +     - Mandatory
> +     - A block of memory shall only be freed if it was allocated by means of a
> +       Standard Library function
> +     -
> +
> +   * - `Rule 22.4 <https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/-/blob/master/R_22_04.c>`_
> +     - Mandatory
> +     - There shall be no attempt to write to a stream which has been opened as
> +       read-only
> +     -
> +
> +   * - `Rule 22.5 <https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/-/blob/master/R_22_05.c>`_
> +     - Mandatory
> +     - A pointer to a FILE object shall not be dereferenced
> +     -
> +
> +   * - `Rule 22.6 <https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/-/blob/master/R_22_06.c>`_
> +     - Mandatory
> +     - The value of a pointer to a FILE shall not be used after the associated
> +       stream has been closed
> +     -
> -- 
> 2.25.1
> 
Re: [PATCH] docs/misra: adds Mandatory rules
Posted by Jan Beulich 11 months, 3 weeks ago
On 12.05.2023 01:22, Stefano Stabellini wrote:
> From: Stefano Stabellini <stefano.stabellini@amd.com>
> 
> Add the Mandatory rules agreed by the MISRA C working group to
> docs/misra/rules.rst.
> 
> Signed-off-by: Stefano Stabellini <stefano.stabellini@amd.com>

Slightly hesitantly
Acked-by: Jan Beulich <jbeulich@suse.com>
primarily because I don't see the point in enumerating / discussing
rules we're not affected by (as long as this list is for the
hypervisor only).

Jan
Re: [PATCH] docs/misra: adds Mandatory rules
Posted by Luca Fancellu 11 months, 3 weeks ago

> On 12 May 2023, at 00:22, Stefano Stabellini <sstabellini@kernel.org> wrote:
> 
> From: Stefano Stabellini <stefano.stabellini@amd.com>
> 
> Add the Mandatory rules agreed by the MISRA C working group to
> docs/misra/rules.rst.
> 
> Signed-off-by: Stefano Stabellini <stefano.stabellini@amd.com>
> ---

Hi Stefano,

I’ve tried this patch with our integration tool xen-analysis.py and it works, I’ve been
able to successfully produce cppcheck reports.

I’ve checked links and rule text against the misra C docs, everything looks fine.

Reviewed-by: Luca Fancellu <luca.fancellu@arm.com>
Tested-by: Luca Fancellu <luca.fancellu@arm.com>