From: Nicola Vetrini <nicola.vetrini@bugseng.com>
To: Dmytro Prokopchuk1 <dmytro_prokopchuk1@epam.com>
Cc: xen-devel@lists.xenproject.org,
"Doug Goldstein" <cardoe@cardoe.com>,
"Stefano Stabellini" <sstabellini@kernel.org>,
"Andrew Cooper" <andrew.cooper3@citrix.com>,
"Anthony PERARD" <anthony.perard@vates.tech>,
"Michal Orzel" <michal.orzel@amd.com>,
"Jan Beulich" <jbeulich@suse.com>,
"Julien Grall" <julien@xen.org>,
"Roger Pau Monné" <roger@xenproject.org>
Subject: Re: [PATCH] misra: deviate C library-style functions from Misra C:2012 rule 11.8
Date: Tue, 29 Sep 2026 11:11:07 +0200 [thread overview]
Message-ID: <d8d26f6890d69c12b017a1fb0b11b875@bugseng.com> (raw)
In-Reply-To: <4abcb11ef287170ced74935cbee60c90058c1307.1790671787.git.dmytro_prokopchuk1@epam.com>
On 2026-09-29 11:03, Dmytro Prokopchuk1 wrote:
> bsearch(), memchr(), memchr_inv(), strchr(), strpbrk(), strrchr() and
> strstr() all accept a const pointer/object but return a non-const
> pointer
> to the matched element or byte, matching their standard C library
> interfaces. The const qualifier is deliberately stripped so that
> callers
> searching a non-const object get back a mutable pointer to it. Fixing
> this would require changing the public API, so document these uses as
> deviations instead.
>
> Update docs/misra/rules.rst to note that this class of double-use
> library functions is deviated on a per-function basis.
>
> Signed-off-by: Dmytro Prokopchuk <dmytro_prokopchuk1@epam.com>
> ---
> Test CI pipeline:
> https://gitlab.com/xen-project/people/dimaprkp4k/xen/-/pipelines/2892411430
> ---
> automation/eclair_analysis/ECLAIR/deviations.ecl | 9 +++++++++
> docs/misra/deviations.rst | 9 +++++++++
> docs/misra/rules.rst | 5 ++++-
> 3 files changed, 22 insertions(+), 1 deletion(-)
>
> diff --git a/automation/eclair_analysis/ECLAIR/deviations.ecl
> b/automation/eclair_analysis/ECLAIR/deviations.ecl
> index 33d508a2fb..0b87bd1d6f 100644
> --- a/automation/eclair_analysis/ECLAIR/deviations.ecl
> +++ b/automation/eclair_analysis/ECLAIR/deviations.ecl
> @@ -445,6 +445,15 @@ write or not"
>
> -config=MC3A2.R11.8,reports+={safe,"any_area(any_loc(text(^.*__hvm_copy.*HVMCOPY_to_guest
> doesn't modify.*$)))"}
> -doc_end
>
> +-doc_begin="Functions bsearch(), memchr(), memchr_inv(), strchr(),
> strpbrk(),
> +strrchr() and strstr() accept a const pointer/object and return a
> non-const
> +pointer to the matched element or byte, matching their standard C
> library
> +interfaces. The const qualifier is deliberately stripped so that
> callers
> +searching a non-const object get back a mutable pointer. This use is
> deemed
> +safe."
> +-config=MC3A2.R11.8,reports+={safe,"any_area(any_loc(file(^xen/include/xen/bsearch\\.h|xen/lib/memchr\\.c|xen/lib/memchr_inv\\.c|xen/lib/strchr\\.c|xen/lib/strpbrk\\.c|xen/lib/strrchr\\.c|xen/lib/strstr\\.c$)))"}
> +-doc_end
> +
I would say that the regex can be more compact than this. (e.g.
file(^xen/include/bsearch\\.h$||^xen/lib/(memchr|memchr_inv|strchr|strpbrk|strrchr|strstr)\\.c$)
)
> -doc_begin="This construct is used to check if the type is scalar, and
> for this purpose the use of 0 as a null pointer constant is
> deliberate."
> -config=MC3A2.R11.9,reports+={deliberate,
> "any_area(any_loc(any_exp(macro(^__ACCESS_ONCE$))))"
> }
> diff --git a/docs/misra/deviations.rst b/docs/misra/deviations.rst
> index b048309596..e3ad3545bc 100644
> --- a/docs/misra/deviations.rst
> +++ b/docs/misra/deviations.rst
> @@ -427,6 +427,15 @@ Deviations related to MISRA C:2012 Rules:
> readability.
> - Tagged as `safe` for ECLAIR.
>
> + * - R11.8
> + - Functions bsearch(), memchr(), memchr_inv(), strchr(),
> strpbrk(),
> + strrchr() and strstr() accept a const pointer/object and return
> a
> + non-const pointer to the matched element or byte, matching
> their
> + standard C library interfaces. The const qualifier is
> deliberately
> + stripped so that callers searching a non-const object get back
> a
> + mutable pointer. This use is deemed safe.
> + - Tagged as `safe` for ECLAIR.
> +
> * - R11.9
> - __ACCESS_ONCE uses an integer, which happens to be zero, as a
> compile time check. The typecheck uses a cast. The usage of
> zero or other
> diff --git a/docs/misra/rules.rst b/docs/misra/rules.rst
> index c9bbab6c08..644e897558 100644
> --- a/docs/misra/rules.rst
> +++ b/docs/misra/rules.rst
> @@ -469,7 +469,10 @@ maintainers if you want to suggest a change.
> * - `Rule 11.8
> <https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/-/blob/master/R_11_08.c>`_
> - Required
> - A cast shall not remove any const or volatile qualification
> from the type pointed to by a pointer
> - -
> + - Some standard C library-style functions are inherently
> double-use,
> + accepting a const argument and returning a non-const pointer
> into
> + it so that callers searching a non-const object get back a
> + mutable pointer. Such uses are deviated on a per-function
> basis.
>
> * - `Rule 11.9
> <https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite/-/blob/master/R_11_09.c>`_
> - Required
--
Nicola Vetrini, B.Sc.
Software Engineer
BUGSENG (https://bugseng.com)
LinkedIn: https://www.linkedin.com/in/nicola-vetrini-a42471253
next prev parent reply other threads:[~2026-09-29 9:11 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-29 9:03 [PATCH] misra: deviate C library-style functions from Misra C:2012 rule 11.8 Dmytro Prokopchuk1
2026-09-29 9:11 ` Nicola Vetrini [this message]
2026-09-29 13:40 ` Jan Beulich
2026-09-29 14:56 ` Nicola Vetrini
2026-09-29 15:11 ` Jan Beulich
2026-09-29 17:52 ` Nicola Vetrini
2026-10-01 12:39 ` Andrew Cooper
2026-10-01 12:43 ` Jan Beulich
2026-10-01 13:16 ` Andrew Cooper
2026-10-01 13:35 ` Nicola Vetrini
2026-10-04 21:05 ` Nicola Vetrini
2026-10-13 14:31 ` Dmytro Prokopchuk1
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=d8d26f6890d69c12b017a1fb0b11b875@bugseng.com \
--to=nicola.vetrini@bugseng.com \
--cc=andrew.cooper3@citrix.com \
--cc=anthony.perard@vates.tech \
--cc=cardoe@cardoe.com \
--cc=dmytro_prokopchuk1@epam.com \
--cc=jbeulich@suse.com \
--cc=julien@xen.org \
--cc=michal.orzel@amd.com \
--cc=roger@xenproject.org \
--cc=sstabellini@kernel.org \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.