[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: xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: Dmytro Prokopchuk <dmytro_prokopchuk1@xxxxxxxx>
  • Date: Mon, 2 Nov 2026 12:39:19 +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=dzF5ZIL10DZ4y6+BdoYzA09ao49u041PnHz6hjIkOYc=; b=AbmmgiHvRiqaMMBlTGd0Gd/IYwMINh5gk61Ds+M1m+NFYacKbiGyKHuMdNKMxm8BEwaQNhzBO4tz2CFAMnW3B6XKypCmtdnV1iuWnmFpKPr7/adnSG4Ku3sJE8ZUbhcwDhiFUgfUz01+vliYUNYNg39nJcQRa0MdmhEOMjFFeWCCwG2CFiA+J+2adgjy4XWX6y4t71E75DBlMY9ddCKGv4PuhWx/LpI7aIVuHVGNJXWAFKOjkYCy3n6p+UzKuuB23+YeW5oy+UZJJ+9zWdIA8CTpZq5DkiLAH6mUuRPYbyYcD+I8mwJ+8jIPNgR7y+5rXGJoSxkW8i0WtgV4gu77yQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=p7rBQEopWZ7Dx4yl7v2fYL76r0l3ld0VA/c9Nf0PBhU8cW6K+gN2vVTIpBhGwePbKIzg6VJJOxah38EEeYEeDpHUvJtJrDvqYxHzA2tsxw2QKsmF44OZ0KuuyL62XljTtlSrYgIVpH3CGd0NKbG076g7D8NhSnnQId3BnmsZ4WZLxzqN3Ye+XWakBMeLM1vLoZum5remdAGlkBNDEp4/KS6YdMTRSYmu70OfGuWLRWRZf5CeIQfulw9ca5LnETUn2CghNEZPVsOujLWKqGRP++10zDEU8AqflrlmvvbJR8F2piHQGKDwtir3L4gv9TsxIGb+Bv0SyzwFjugzNRiC0A==
  • 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;
  • Delivery-date: Mon, 02 Nov 2026 10:39:25 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>



On 11/2/26 12:37, Dmytro Prokopchuk wrote:


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

Sure, will do in v3.


Jan


BR, Dmytro.



 


Rackspace

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