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

Re: [PATCH] misra: deviate C library-style functions from Misra C:2012 rule 11.8


  • To: Jan Beulich <jbeulich@xxxxxxxx>, Andrew Cooper3 <andrew.cooper3@xxxxxxxxxx>
  • From: Nicola Vetrini <nicola.vetrini@xxxxxxxxxxx>
  • Date: Tue, 29 Sep 2026 19:52:52 +0200
  • Arc-authentication-results: i=1; bugseng.com; arc=none smtp.remote-ip=162.55.131.47
  • Arc-message-signature: i=1; d=bugseng.com; s=openarc; a=rsa-sha256; c=relaxed/relaxed; t=1790704373; h=MIME-Version:Date:From:To:Cc:Subject:In-Reply-To:References: Message-ID:X-Sender:Organization:Content-Type: Content-Transfer-Encoding; bh=lwdcqZBsBN5quqmne56Qas7ABZJkiiSTTk6SQKKainc=; b=BU6B5/Cu+6uCm0lHiZqCPypUZwZYFWrh2izVEhqooDeApGuBd0FfxM/FEIQio2ijDKM4 D8KJeaaVy6W/OmsbUB82/rPmal4NpQA/Y6GsbmHjKhnQbzX5p/B26u9SHpXpkPwz8k3fD XY/6/8NFzzp9iJiJjEVN9BsPb1r5un7b/RWbYylPlpyblBTWdYKLXpv8S71CzkFvBgwcw rQu48vPvan6scnwRW5VmlN+7ognAk9MoTq350s4CEKO+7qILxI1cFO4QBMEhqONOMGzF/ Evj2Ek8vfYhMkWr3+Vo/hToJeZox26KBRKztlegnLY8fig9mNgijygdD6RsUaIbqQI6Ao HJ5SkhL9Gq3CJEy4bNKwr+QXjT/cCuz+egD4GScVWwe0dDvfS8AH69F8w4s1d/gTiwTj/ aJrdYxUJdbTuGCM0hzOA4syocIpALZ1puVnEt7bI+9CnA9I/Iv5GHkJ3VJQ8yZlp15W46 5t+/ugWYKfc1ruxV+h1PIXA2e4vuTGlUbGbX5rlB6F6tREAlNdVcQEKEwGAVu8Lzzp7L+ QqvRqTnUFdhHNybC1VdQDmvY3BbhEnUn14NoXqncgs8SBuTwjZw8WsQBTppA8X/4GkHAU Jc8vmGVS5bSgj4CtSQCD7UWk+yNIe3Z3oviuFrBvLvCmjrhvV7cgAHNaSIx+Dkw=
  • Arc-seal: i=1; d=bugseng.com; s=openarc; a=rsa-sha256; cv=none; t=1790704373; b=amEbrz2MwrkJ4c/5HksIXCBEAyt+tUR3qn7H8iHblAIqPn4Jrj6mtgg/uCYMHrdg1Hw0 dTd3aJ7/wDcZmvn9B4VX1hYaC4iWMlsqSqd+zFEsXgC0U4TSqLlgNNcLGSyo+hYFNNHCY owPkXbrnAvAheTaW/+a2WojDB5P/dg43CsWrh9ISyxZW2DTljyPuFFdwyzsF0lXiiS6IJ IImtGOfF9Z28b60ZyIb9kT3nS3XO9996dK/9PGDD3RcNGIDA1FxYXBteMkHHtzfpMY9Xd e2bzdO1SbpNrZWO8vmRFzPXlZGorLXkM7uZP0UzwGs4VoY2yn7PI6UG9dJjJez7GyWCS+ FjBG7zxT0LxclX1uRktwi8LjKZ79UYWjAbZiwFZBsBc8ZjvxU/UkOZZ2zwPpE45aSFf0M NyBKTvBXPoKzlUtNZiL8WE6QT3j3fIeKz+nyMYIqoSE6gr7WxTbRqEzkofGVjb0C1MOhG eW2VwlE+pZ76WlwI6Xg0J/b/JTg3hpBEw8xycPgeUxTCIiolmHGUWsxt3420ZB8LZZyWT VeC8gD4OsraOxwgrl0XPdflmJ89KrKu3qObAdaECtAJQOnaEYEyTUBwT7a2pmwD19QHkQ MQjZacOU7OL9fp7cZum3EDkhipEUObI5ElAOK4zLzn4A6a7ofr5AaW4/4rV4Vaw=
  • Authentication-results: eu.smtp.expurgate.cloud; none
  • Authentication-results: bugseng.com; arc=none smtp.remote-ip=162.55.131.47
  • Cc: Dmytro Prokopchuk1 <dmytro_prokopchuk1@xxxxxxxx>, Doug Goldstein <cardoe@xxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Julien Grall <julien@xxxxxxx>, Roger Pau Monné <roger@xxxxxxxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • Delivery-date: Tue, 29 Sep 2026 17:53:04 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 2026-09-29 17:11, Jan Beulich wrote:
On 29.09.2026 16:56, Nicola Vetrini wrote:
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@xxxxxxxx>

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?

From glibc 2.43:

# define __glibc_const_generic(PTR, CTYPE, CALL)        \
  _Generic (0 ? (PTR) : (void *) 1,                     \
            const void *: (CTYPE) (CALL),               \
            default: CALL)

while the declarations still are e.g.

extern void *memchr (const void *__s, int __c, size_t __n)
      __THROW __attribute_pure__ __nonnull ((1));

(and hence the implementation still - necessarily - casts away
const-ness).


Ok, will look into that

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).

As this keeps coming up, we surely want to discuss / progress this move.

Jan

That makes a lot of sense. We could add to the next community call or maintainers/committers call to present the problem and propose a way forward so that all stakeholders are aware. From my side, I can explain what moving from one to the other can entail in terms of static analysis, while others (e.g. Andrew Cooper) may expand a bit on specific C11/C18 features is desirable aside from safety.

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



 


Rackspace

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