Merge remote-tracking branch 'origin/master'

master
wuhaoyang 10 months ago
commit 5529fed8a2
  1. 6
      sonar-keyware-plugins-cxx/src/main/java/com/keyware/sonar/cxx/rules/checkers/NumericalCopyChecker.java
  2. 6
      sonar-keyware-plugins-cxx/src/test/resources/com/keyware/sonar/cxx/rules/checkers/NumericalCopyChecker.cc

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

@ -4,8 +4,8 @@ class MyClass {
private: private:
std::array<int, 10> privateArray; std::array<int, 10> privateArray;
public: public:
// 假设初始化已经在构造函数或其他地方完成 // 假设初始化已经在构造函数或其他地方完成
// 返回的是私有数组的副本 // 返回的是私有数组的副本
// const std::array<int, 10> getPrivateArrayRef() const { // const std::array<int, 10> getPrivateArrayRef() const {
// return privateArray; // return privateArray;
// } // }
@ -15,7 +15,7 @@ public:
return privateArray; // error return privateArray; // error
} }
// 返回的是私有数组的指针 // // 返回的是私有数组的指针
int* getPrivateArrayPtr() { int* getPrivateArrayPtr() {
return privateArray.data(); // error return privateArray.data(); // error
} }

Loading…
Cancel
Save