From 000f2d50e5a1116afc8bd1791ad7db3759f6b8a4 Mon Sep 17 00:00:00 2001 From: renfengshan <1535889807@qq.com> Date: Sun, 4 Feb 2024 15:02:55 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E2=80=9C=E5=BA=94=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E8=AF=A5=E7=A7=81=E6=9C=89=E6=95=B0=E5=80=BC=E7=9A=84?= =?UTF-8?q?=E5=89=AF=E6=9C=AC=E2=80=9D=E5=87=86=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sonar/cxx/rules/checkers/NumericalCopyChecker.java | 6 ++++-- .../sonar/cxx/rules/checkers/NumericalCopyChecker.cc | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/sonar-keyware-plugins-cxx/src/main/java/com/keyware/sonar/cxx/rules/checkers/NumericalCopyChecker.java b/sonar-keyware-plugins-cxx/src/main/java/com/keyware/sonar/cxx/rules/checkers/NumericalCopyChecker.java index 4b9c1df..daa490b 100644 --- a/sonar-keyware-plugins-cxx/src/main/java/com/keyware/sonar/cxx/rules/checkers/NumericalCopyChecker.java +++ b/sonar-keyware-plugins-cxx/src/main/java/com/keyware/sonar/cxx/rules/checkers/NumericalCopyChecker.java @@ -42,8 +42,10 @@ public class NumericalCopyChecker extends SquidCheck {//当私有数组 for (AstNode ast : descendan) { List descendants = ast.getDescendants(CxxGrammarImpl.expression); for (AstNode des : descendants) { - if (lists.contains(des.getTokenValue())) { - getContext().createLineViolation(this, "应返回该私有数值的副本", des); + if ("return".equals(des.getParent().getTokenValue())){ + if (lists.contains(des.getTokenValue())) { + getContext().createLineViolation(this, "应返回该私有数值的副本", des); + } } } } diff --git a/sonar-keyware-plugins-cxx/src/test/resources/com/keyware/sonar/cxx/rules/checkers/NumericalCopyChecker.cc b/sonar-keyware-plugins-cxx/src/test/resources/com/keyware/sonar/cxx/rules/checkers/NumericalCopyChecker.cc index 77f53eb..714ebc3 100644 --- a/sonar-keyware-plugins-cxx/src/test/resources/com/keyware/sonar/cxx/rules/checkers/NumericalCopyChecker.cc +++ b/sonar-keyware-plugins-cxx/src/test/resources/com/keyware/sonar/cxx/rules/checkers/NumericalCopyChecker.cc @@ -4,8 +4,8 @@ class MyClass { private: std::array privateArray; public: - // 假设初始化已经在构造函数或其他地方完成 - // 返回的是私有数组的副本 +// 假设初始化已经在构造函数或其他地方完成 +// 返回的是私有数组的副本 // const std::array getPrivateArrayRef() const { // return privateArray; // } @@ -15,7 +15,7 @@ public: return privateArray; // error } - // 返回的是私有数组的指针 +// // 返回的是私有数组的指针 int* getPrivateArrayPtr() { return privateArray.data(); // error }