@@ -636,6 +636,36 @@ static std::unordered_map<std::string, BuiltinLibraryFunction> createBuiltinLibr
636636 v.tokvalue = nullptr ;
637637 return v;
638638 };
639+ functions[" strcmp" ] = [](const std::vector<ValueFlow::Value>& args) {
640+ if (args.size () != 2 )
641+ return ValueFlow::Value::unknown ();
642+ const ValueFlow::Value& lhs = args[0 ];
643+ if (!(lhs.isTokValue () && lhs.tokvalue ->tokType () == Token::eString))
644+ return ValueFlow::Value::unknown ();
645+ const ValueFlow::Value& rhs = args[1 ];
646+ if (!(rhs.isTokValue () && rhs.tokvalue ->tokType () == Token::eString))
647+ return ValueFlow::Value::unknown ();
648+ ValueFlow::Value v (getStringLiteral (lhs.tokvalue ->str ()).compare (getStringLiteral (rhs.tokvalue ->str ())));
649+ ValueFlow::combineValueProperties (lhs, rhs, v);
650+ return v;
651+ };
652+ functions[" strncmp" ] = [](const std::vector<ValueFlow::Value>& args) {
653+ if (args.size () != 3 )
654+ return ValueFlow::Value::unknown ();
655+ const ValueFlow::Value& lhs = args[0 ];
656+ if (!(lhs.isTokValue () && lhs.tokvalue ->tokType () == Token::eString))
657+ return ValueFlow::Value::unknown ();
658+ const ValueFlow::Value& rhs = args[1 ];
659+ if (!(rhs.isTokValue () && rhs.tokvalue ->tokType () == Token::eString))
660+ return ValueFlow::Value::unknown ();
661+ const ValueFlow::Value& len = args[2 ];
662+ if (!len.isIntValue ())
663+ return ValueFlow::Value::unknown ();
664+ ValueFlow::Value v (getStringLiteral (lhs.tokvalue ->str ())
665+ .compare (0 , len.intvalue , getStringLiteral (rhs.tokvalue ->str ()), 0 , len.intvalue ));
666+ ValueFlow::combineValueProperties (lhs, rhs, v);
667+ return v;
668+ };
639669 functions[" sin" ] = [](const std::vector<ValueFlow::Value>& args) {
640670 if (args.size () != 1 )
641671 return ValueFlow::Value::unknown ();
@@ -1164,6 +1194,7 @@ static ValueFlow::Value executeImpl(const Token* expr, ProgramMemory& pm, const
11641194 if (expr->hasKnownIntValue () && !expr->isAssignmentOp () && expr->str () != " ," )
11651195 return expr->values ().front ();
11661196 if ((value = expr->getKnownValue (ValueFlow::Value::ValueType::FLOAT )) ||
1197+ (value = expr->getKnownValue (ValueFlow::Value::ValueType::TOK )) ||
11671198 (value = expr->getKnownValue (ValueFlow::Value::ValueType::ITERATOR_START )) ||
11681199 (value = expr->getKnownValue (ValueFlow::Value::ValueType::ITERATOR_END )) ||
11691200 (value = expr->getKnownValue (ValueFlow::Value::ValueType::CONTAINER_SIZE ))) {
0 commit comments