cppcheck icon indicating copy to clipboard operation
cppcheck copied to clipboard

MISRA 10.3 improvements

Open wienans opened this issue 10 months ago • 1 comments

Updated the check for misra 10.3 based on the misra examples https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/Example-Suite

also added the examples as tests

wienans avatar Mar 03 '25 17:03 wienans

@danmar actually handling this https://github.com/danmar/cppcheck/blob/75ec331ea1d76cc36abb49d701a6017c0c3497c2/addons/test/misra/misra-test.c#L880-L883 i find actually hard. It generates the following token stream and currently generates a 10.3 Warning due to char and signed char essential type category mismatch.

    <token id="594add3b56b0" file="project/src/test.c" linenr="22" column="1" str="static" scope="594add381040" type="name"/>
    <token id="594add3b9740" file="project/src/test.c" linenr="22" column="8" str="char" scope="594add381040" type="name"/>
    <token id="594add3a5e00" file="project/src/test.c" linenr="22" column="13" str="*" scope="594add381040" type="op" isArithmeticalOp="true"/>
    <token id="594add382cf0" file="project/src/test.c" linenr="22" column="15" str="misra_11_8" scope="594add381040" type="name" function="594add34da70"/>
    <token id="594add32f260" file="project/src/test.c" linenr="22" column="25" str="(" scope="594add381040" link="594add3bc560" valueType-type="char" valueType-sign="signed" valueType-pointer="1" valueType-reference="None"/>
    <token id="594add3bc280" file="project/src/test.c" linenr="22" column="26" str="const" scope="594add381040" type="name"/>
    <token id="594add37b820" file="project/src/test.c" linenr="22" column="32" str="char" scope="594add381040" type="name"/>
    <token id="594add33f8e0" file="project/src/test.c" linenr="22" column="37" str="*" scope="594add381040" type="op" isArithmeticalOp="true"/>
    <token id="594add3bc3e0" file="project/src/test.c" linenr="22" column="38" str="str" scope="594add381040" type="name" varId="6" exprId="6" variable="594add337bb0" valueType-type="char" valueType-sign="signed" valueType-pointer="1" valueType-constness="1" valueType-reference="None"/>
    <token id="594add3bc560" file="project/src/test.c" linenr="22" column="41" str=")" scope="594add381040" link="594add32f260"/>
    <token id="594add3bc6e0" file="project/src/test.c" linenr="22" column="43" str="{" scope="594add389460" link="594add30c3d0"/>
    <token id="594add3bc750" file="project/src/test.c" linenr="23" column="5" str="return" scope="594add389460" type="name" astOperand1="594add32ef20" valueType-type="char" valueType-sign="signed" valueType-pointer="1" valueType-reference="None"/>
    <token id="594add32ef20" file="project/src/test.c" linenr="23" column="12" str="(" scope="594add389460" isCast="true" link="594add3bcaa0" exprId="1073741840" values="594add3b8c70" astParent="594add3bc750" astOperand1="594add30b1a0" valueType-type="char" valueType-sign="signed" valueType-pointer="1" valueType-reference="None"/>
    <token id="594add3bc7c0" file="project/src/test.c" linenr="23" column="13" str="char" scope="594add389460" type="name"/>
    <token id="594add3bc940" file="project/src/test.c" linenr="23" column="18" str="*" scope="594add389460" type="op" isArithmeticalOp="true"/>
    <token id="594add3bcaa0" file="project/src/test.c" linenr="23" column="19" str=")" scope="594add389460" link="594add32ef20"/>
    <token id="594add30b1a0" file="project/src/test.c" linenr="23" column="20" str="str" scope="594add389460" type="name" varId="6" exprId="6" variable="594add337bb0" astParent="594add32ef20" valueType-type="char" valueType-sign="signed" valueType-pointer="1" valueType-constness="1" valueType-reference="None"/>
    <token id="594add30b210" file="project/src/test.c" linenr="23" column="23" str=";" scope="594add389460"/>
    <token id="594add30c3d0" file="project/src/test.c" linenr="24" column="1" str="}" scope="594add389460" link="594add3bc6e0"/>

in case of the Cast we look at the actual cast type and chek if the valueType token is str="char" and doesn't have the signed and unsinged flags. But the return token does not have this link (at least to my knowledge) to the type definition token to the return type given in the function definition. Currently i didn't find a good solution to handle this. Any suggestions?

wienans avatar Mar 09 '25 19:03 wienans