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

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


  • To: Jan Beulich <jbeulich@xxxxxxxx>
  • From: Dmytro Prokopchuk <dmytro_prokopchuk1@xxxxxxxx>
  • Date: Mon, 2 Nov 2026 12:37:17 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=Ca4HOpVLcNuIyEyBUpsPqC7WaTK3GpBsh39cN6RRjho=; b=JgfP05Skly3Nt7l4gc5ZEWSiNiNMandN3gy1pTybFpTV8owV2rhIDOBrxsgG5wrosfmZbFrgJh8KwwjQCZY3VvLDn/uZVGLyzTcSMt2EqyKWVSgsj9/JYg28wA57Efzg2FsWu1cpa8grv5wmbIeKVfA8ZRvj6e+lzPzBwJKCEHq2GoSGhtlI0BxXIKIU15AcX8+rFW1jAvP2dU77311dkka23qHl2YiYvdNPcbzMlr9ScpVMsLnKMz6iODZK/Kul3izBp+HlQOXCJqVBiVOH942FQU99FharrjcZqGNzqpF1rc2gsGl45YmqBdSHmrB8wF49kJEo27g3omgSkxV/fw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=AVYko8SU2NdwMWoX7EJiJe6XnvSS685H3oNldViJ8G/mX7/WsZgNwjaX74hS+68MTMTHeTVa5pjBojl+Z5FkIZ/AwgSlf1XLGistx34QIekauCewYpphLJwfePBXu1M8KCEfcFRpHpFWdt9RI/ZWsd7hV0O+Nf7H7O6t9QZZkABuF2RbdL8luIM8gHjfEKpSfznT4Nj6Rz4vIjrWTa0yptTFJRKF63+qXPZMqFttxJJlKVbAg3cPy4j9e0HnPx3f6JD1xBJBeAam+b3FUiLh4Q+l8ckHTD1Nf7bTFrAgV2vVaCggmY4eR3kwcRT3EOC3MjDx0k85wZ074N5tSXgTTQ==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=epam.com header.i="@epam.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck"
  • Authentication-results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=epam.com;
  • Cc: Nicola Vetrini <nicola.vetrini@xxxxxxxxxxx>, Doug Goldstein <cardoe@xxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Julien Grall <julien@xxxxxxx>, Roger Pau Monné <roger@xxxxxxxxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Mon, 02 Nov 2026 10:37:29 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>



On 10/26/26 13:09, Jan Beulich wrote:
On 19.10.2026 12:41, Dmytro Prokopchuk1 wrote:
bsearch(), memchr(), 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 casts in these implementations strip const so that callers searching
a non-const object get back a mutable pointer. Fixing this would require
changing the public API, so document these uses as deviations instead.

Imo "public API" is misleading here, as it could mean "public interface",
which isn't affected here at all. Then ...

Agreed. I'll reword the last sentence to:
"Avoiding the casts would require deviating from the standard C library
prototypes of these functions, 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>

Acked-by: Jan Beulich <jbeulich@xxxxxxxx>

Albeit there another minor remark:

--- a/automation/eclair_analysis/ECLAIR/deviations.ecl
+++ b/automation/eclair_analysis/ECLAIR/deviations.ecl
@@ -450,6 +450,14 @@ write or not"
  
-config=MC3A2.R11.8,reports+={safe,"any_area(any_loc(file(hvm_guestcopy)&&text(^.*__hvm_copy.*HVMCOPY_to_guest
 doesn't modify.*$)))"}
  -doc_end
+-doc_begin="Functions bsearch(), memchr(), 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
+casts in these implementations strip const so that a search of a non-const
+object yields 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|strchr|strpbrk|strrchr|strstr)\\.c$)))"}
+-doc_end

Can't we fold strchr and strrchr here, e.g. as simple as 
(memchr|str+chr|strpbrk|strstr)?



Jan




 


Rackspace

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