You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* @description Arrays should not be used in interfaces. Arrays degenerate to pointers when passed as parameters. This array decay problem has long been known to be a source of errors. Consider using std::vector or encapsulating the array in an Array class.
* @kind problem
* @problem.severity recommendation
* @precision high
* @id cpp/array-in-interface
* @tags reliability
* readability
* language-features
* external/jsf
*/
import cpp
predicatecontainsArray(Typet){
tinstanceofArrayType
or
containsArray(t.(PointerType).getBaseType())
or
containsArray(t.(SpecifiedType).getBaseType())
or
containsArray(t.getUnderlyingType())and
notexists(TypedefTypeallowed|allowed=t|
allowed.hasGlobalOrStdName("jmp_buf")or
allowed.hasGlobalOrStdName("va_list")
)
}
predicatefunctionApiViolation(MemberFunctionf){
f.isPublic()and
containsArray(f.getAParameter().getType())
}
fromMemberFunctionm
where
functionApiViolation(m)and
notm.getDeclaringType()instanceofStruct
selectm,"Raw arrays should not be used in interfaces. A container class should be used instead."