Where is the listing in this code?

I have some lines of my code that are returning an error from our static code analyzer.

This parser is programmed with clang, and the source code for the rule that is broken is pretty simple:

// For each cast expression in the code 
bool VisitCastExpr(CastExpr *castExpr){
    string errorMsg;
    string CastName = castExpr->getCastKindName();
    // If cast is from pointer to everything different than an integer, add violation 
    if((castExpr->getCastKind() == CK_MemberPointerToBoolean)||(castExpr->getCastKind() == CK_PointerToBoolean)||(castExpr->getCastKind() == CK_CPointerToObjCPointerCast)||(castExpr->getCastKind() == CK_BlockPointerToObjCPointerCast)||(castExpr->getCastKind() == CK_AnyPointerToBlockPointerCast)){
        errorMsg = "Forbidden cast "+CastName+" from pointer to non-integer type";
        addViolation(castExpr,this,errorMsg);
    }
    return true; 
}

      

So basically it just adds a violation when some kind of listing (implicit or explicit) is executed from a pointer to something other than an integer.

Here is one of the expressions that returns an error:

if(st_parametre_embarque.qs_nom.contains("PAR")){

...

st_parametre_embarque

is just a structure and the field qs_nom

is QString

.

The Qstring :: contains () method returns boolean.

Here is a report of the violation given by the code analyzer:

Forbidden PointerToBoolean cast from pointer to non-integer type

So, I really don't see where there could be castExpr

, more than that, from a pointer to a boolean.

+3


source to share


1 answer


Before Qt5, QString::contains

returned QBool

instead of bool

. This value must be converted to bool somehow, and the static analyzer decided that it is implicit. Try making an explicit comparison with a boolean constant (i.e. Call operator==(QBool, bool)

) and see if a static analyzer should follow it.



+5


source







All Articles