| 558 | } |
| 559 | |
| 560 | void CheckFunctionsImpl::memsetInvalid2ndParam() |
| 561 | { |
| 562 | // FIXME: |
| 563 | // Replace this with library configuration. |
| 564 | // For instance: |
| 565 | // <arg nr="2"> |
| 566 | // <not-float/> |
| 567 | // <warn possibleIntValue=":-129,256:" severity="warning" msg="..."/> |
| 568 | // </arg> |
| 569 | |
| 570 | const bool printPortability = mSettings.severity.isEnabled(Severity::portability); |
| 571 | const bool printWarning = mSettings.severity.isEnabled(Severity::warning); |
| 572 | if (!printWarning && !printPortability) |
| 573 | return; |
| 574 | |
| 575 | logChecker("CheckFunctions::memsetInvalid2ndParam"); // warning,portability |
| 576 | |
| 577 | const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase(); |
| 578 | for (const Scope *scope : symbolDatabase->functionScopes) { |
| 579 | for (const Token* tok = scope->bodyStart->next(); tok && (tok != scope->bodyEnd); tok = tok->next()) { |
| 580 | if (!Token::simpleMatch(tok, "memset (")) |
| 581 | continue; |
| 582 | |
| 583 | const std::vector<const Token *> args = getArguments(tok); |
| 584 | if (args.size() != 3) |
| 585 | continue; |
| 586 | |
| 587 | // Second parameter is zero literal, i.e. 0.0f |
| 588 | const Token * const secondParamTok = args[1]; |
| 589 | if (Token::Match(secondParamTok, "%num% ,") && MathLib::isNullValue(secondParamTok->str())) |
| 590 | continue; |
| 591 | |
| 592 | // Check if second parameter is a float variable or a float literal != 0.0f |
| 593 | if (printPortability && astIsFloat(secondParamTok,false)) { |
| 594 | memsetFloatError(secondParamTok, secondParamTok->expressionString()); |
| 595 | } |
| 596 | |
| 597 | if (printWarning && secondParamTok->isNumber()) { // Check if the second parameter is a literal and is out of range |
| 598 | const MathLib::bigint value = MathLib::toBigNumber(secondParamTok); |
| 599 | const long long sCharMin = mSettings.platform.signedCharMin(); |
| 600 | const long long uCharMax = mSettings.platform.unsignedCharMax(); |
| 601 | if (value < sCharMin || value > uCharMax) |
| 602 | memsetValueOutOfRangeError(secondParamTok, secondParamTok->str()); |
| 603 | } |
| 604 | } |
| 605 | } |
| 606 | } |
| 607 | |
| 608 | void CheckFunctionsImpl::memsetFloatError(const Token *tok, const std::string &var_value) |
| 609 | { |
no test coverage detected