All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nicola Vetrini <nicola.vetrini@bugseng.com>
To: Jan Beulich <jbeulich@suse.com>
Cc: "Dmytro Prokopchuk1" <dmytro_prokopchuk1@epam.com>,
	"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>,
	"Julien Grall" <julien@xen.org>,
	"Roger Pau Monné" <roger@xenproject.org>,
	xen-devel@lists.xenproject.org
Subject: Re: [PATCH] misra: deviate C library-style functions from Misra C:2012 rule 11.8
Date: Tue, 29 Sep 2026 16:56:07 +0200	[thread overview]
Message-ID: <446354d93ae04a07b86d7293705d7e46@bugseng.com> (raw)
In-Reply-To: <0a286fe9-2133-4f28-8fab-59f4e51d1484@suse.com>

On 2026-09-29 15:40, Jan Beulich wrote:
> On 29.09.2026 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>
> 
> When I prepared my 11.8 series [1], I was wondering whether we need to 
> go
> as far as deviating these. Since we now uniformly take gcc5 as minimum
> baseline, there is (at least in theory) the option of using _Generic to
> cover the dual-use. One question there is whether Eclair would 
> recognize
> such - Nicola? After all, looking at e.g. glibc's implementation, the
> functions themselves remain "unsafe" there; it's a macro wrapping them
> which puts the lost qualifier back.
> 

Could you provide a concrete example? In passing, for stronger 
guarantees w.r.t. _Generic it would be better to switch to MISRA C:2012 
Amendment 3, which has specific support for that feature. Keeping AMD2 
and using _Generic weakens a bit the safety argument (though one can do 
an analysis himself, of course).

> Another question is about memchr_inv(): That's not a standard function,
> and hence it also doesn't need to strictly follow the pattern of those
> other functions. In no case should it, imo, be mixed with the standard
> functions without mentioning the difference.
> 
> Jan
> 
> [1] https://lists.xen.org/archives/html/xen-devel/2026-09/msg00036.html

-- 
Nicola Vetrini, B.Sc.
Software Engineer
BUGSENG (https://bugseng.com)
LinkedIn: https://www.linkedin.com/in/nicola-vetrini-a42471253


  reply	other threads:[~2026-09-29 14:56 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
2026-09-29 13:40 ` Jan Beulich
2026-09-29 14:56   ` Nicola Vetrini [this message]
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=446354d93ae04a07b86d7293705d7e46@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.