更新“应返回该私有数值的副本”准则

master
renfengshan 10 months ago
parent 000f2d50e5
commit d4db3b764b
  1. 8
      sonar-keyware-plugins-cxx/src/main/java/com/keyware/sonar/cxx/rules/checkers/NumericalCopyChecker.java
  2. 2
      sonar-keyware-plugins-cxx/src/test/resources/com/keyware/sonar/cxx/rules/checkers/NumericalCopyChecker.cc

@ -42,10 +42,10 @@ public class NumericalCopyChecker extends SquidCheck<Grammar> {//当私有数组
for (AstNode ast : descendan) {
List<AstNode> descendants = ast.getDescendants(CxxGrammarImpl.expression);
for (AstNode des : descendants) {
if ("return".equals(des.getParent().getTokenValue())){
if (lists.contains(des.getTokenValue())) {
getContext().createLineViolation(this, "应返回该私有数值的副本", des);
}
if ("return".equals(des.getParent().getTokenValue()) || des.getTokenValue().contains("0")){
if (lists.contains(des.getTokenValue())) {
getContext().createLineViolation(this, "应返回该私有数值的副本", des);
}
}
}
}

@ -15,7 +15,7 @@ public:
return privateArray; // error
}
// // 返回的是私有数组的指针
// 返回的是私有数组的指针
int* getPrivateArrayPtr() {
return privateArray.data(); // error
}

Loading…
Cancel
Save