From 7dfca8f93b5318b4c5cad175d7596090f6d3ceed Mon Sep 17 00:00:00 2001 From: Luke Cartey Date: Fri, 31 Mar 2023 09:04:48 +0100 Subject: [PATCH] Rule 7.4: Improve performance resolveTypeDefs*() was causing poor performance on OpenPilot due to the number of TypeDefs. The definition of GenericCharPointerType has been switched to use recursion instead for better performance. --- .../StringLiteralAssignedToNonConstChar.ql | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/c/misra/src/rules/RULE-7-4/StringLiteralAssignedToNonConstChar.ql b/c/misra/src/rules/RULE-7-4/StringLiteralAssignedToNonConstChar.ql index 35b43f8323..c93740139b 100644 --- a/c/misra/src/rules/RULE-7-4/StringLiteralAssignedToNonConstChar.ql +++ b/c/misra/src/rules/RULE-7-4/StringLiteralAssignedToNonConstChar.ql @@ -20,13 +20,17 @@ class WideCharPointerType extends PointerType { override string getAPrimaryQlClass() { result = "WideCharPointerType" } } -class GenericCharPointerType extends PointerType { +class GenericCharPointerType extends Type { GenericCharPointerType() { - /* This type resolves to wchar_t* (which is in turn a typedef depending on its implementation) */ - this.resolveTypedefs*() instanceof WideCharPointerType + // A wide char pointer type + this instanceof WideCharPointerType or - /* This type eventually resolves to char* */ - this.resolveTypedefs*() instanceof CharPointerType + // A char pointer type + this.getUnspecifiedType() instanceof CharPointerType + or + // A typedef to any such type. + // Note: wchar_t is usually a typedef, so we cannot just use getUnspecifiedType() here. + this.(TypedefType).getBaseType() instanceof GenericCharPointerType } }