| 626 | } |
| 627 | |
| 628 | void 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; |
nothing calls this directly
no test coverage detected