优化:添加获取判断中参数方式

wuhaoyang
RenFengJiang 8 months ago
parent b2e20c1dec
commit aaee78b3fd
  1. 2
      sonar-keyware-plugins-cxx/src/main/java/com/keyware/sonar/cxx/rules/checkers/CmdDataVerifyChecker.java
  2. 9
      sonar-keyware-plugins-cxx/src/test/resources/com/keyware/sonar/cxx/rules/checkers/CmdDataVerifyChecker.cc

@ -10,6 +10,7 @@ import com.keyware.sonar.cxx.SubscriptionAstVisitor;
import com.sonar.cxx.sslr.api.AstNode;
import com.sonar.cxx.sslr.api.AstNodeType;
import com.sonar.cxx.sslr.api.Grammar;
import org.checkerframework.checker.units.qual.C;
import org.sonar.check.Priority;
import org.sonar.check.Rule;
import org.sonar.cxx.parser.CxxGrammarImpl;
@ -73,6 +74,7 @@ public class CmdDataVerifyChecker extends SquidCheck<Grammar> {
if("if".equals(astNode.getToken().getValue())){
//获取其中的参数
List<AstNode> astNodeList = astNode.getDescendants(CxxGrammarImpl.expressionList);
astNodeList.addAll(astNode.getDescendants(CxxGrammarImpl.condition));
for (AstNode expr:astNodeList) {
lists.add(expr.getToken().getValue());
}

@ -3,13 +3,14 @@
int main() {
std::string command = "echo Hello, World!"; // 要构建的命令
// if(a(command)){
// }
// if(command.contains("/") ){
// }
// if(command == ""){
// }
// 使用system函数执行命令
int result = system(command);
int result = system(command.c_str()); // error
if (result == 0) {
std::cout << "命令执行成功。" << std::endl;

Loading…
Cancel
Save