|
[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
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_endCan'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.
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |