Static analysis - custom rule for ascii characters >127

SLTSLT Posts: 9
edited April 2018 in C/C++test

I have to create a custom rule that checks that ascii characters > 127 are not present.
I have some issues doing it.
Can someone help me?

The rule is:
"Define identifiers shall be as following:
< USER_NAME > length is at most 12 characters and not composed by ascii characters > 127."



  • mstaronmstaron Posts: 26

    You can try to use the following python method:

    use correct indentations, that were removed automatically in this post
    def checkCharValue( node, context ):
    stringName = node.getProperty( 'name' )
    for i in range(0, len(stringName)):
    charName = stringName[i]
    charValue = ord(stringName[i])
    if charValue > 127:"String %s contains character '%s' with value greater than 127: (%d)" % (stringName, charName, charValue))
    return 1

    This method can be added to the appropriate node (in C++Text rule) e.g. for 'String Constant'.
    The example of rule:

Sign In or Register to comment.