MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / checkFormatString

Method checkFormatString

lib/checkio.cpp:628–1366  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

626}
627
628void CheckIOImpl::checkFormatString(const Token * const tok,
629 const Token * const formatStringTok,
630 const Token * argListTok,
631 const bool scan,
632 const bool scanf_s)
633{
634 const bool isWindows = mSettings.platform.isWindows();
635 const bool printWarning = mSettings.severity.isEnabled(Severity::warning);
636 const std::string &formatString = formatStringTok->str();
637
638 // Count format string parameters..
639 int numFormat = 0;
640 int numSecure = 0;
641 bool percent = false;
642 const Token* argListTok2 = argListTok;
643 std::set<int> parameterPositionsUsed;
644 for (auto i = formatString.cbegin(); i != formatString.cend(); ++i) {
645 if (*i == '%') {
646 percent = !percent;
647 } else if (percent && *i == '[') {
648 while (i != formatString.cend()) {
649 if (*i == ']') {
650 numFormat++;
651 if (argListTok)
652 argListTok = argListTok->nextArgument();
653 percent = false;
654 break;
655 }
656 ++i;
657 }
658 if (scanf_s) {
659 numSecure++;
660 if (argListTok) {
661 argListTok = argListTok->nextArgument();
662 }
663 }
664 if (i == formatString.cend())
665 break;
666 } else if (percent) {
667 percent = false;
668
669 bool _continue = false;
670 bool skip = false;
671 std::string width;
672 int parameterPosition = 0;
673 bool hasParameterPosition = false;
674 while (i != formatString.cend() && *i != '[' && !std::isalpha(static_cast<unsigned char>(*i))) {
675 if (*i == '*') {
676 skip = true;
677 if (scan)
678 _continue = true;
679 else {
680 numFormat++;
681 if (argListTok)
682 argListTok = argListTok->nextArgument();
683 }
684 } else if (std::isdigit(*i)) {
685 width += *i;

Callers

nothing calls this directly

Calls 15

isCPPMethod · 0.80
isLibraryTypeMethod · 0.80
isKnownTypeMethod · 0.80
isArrayMethod · 0.80
isArrayOrPointerMethod · 0.80
isUnsignedMethod · 0.80
typesMatchFunction · 0.70
isEnabledMethod · 0.45
strMethod · 0.45
nextArgumentMethod · 0.45
clearMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected