--------------------------------------------------------------------------- Writing string literal is UB ---------------------------------------------------------------------------
| 48 | // Writing string literal is UB |
| 49 | //--------------------------------------------------------------------------- |
| 50 | void CheckStringImpl::stringLiteralWrite() |
| 51 | { |
| 52 | logChecker("CheckString::stringLiteralWrite"); |
| 53 | const SymbolDatabase *symbolDatabase = mTokenizer->getSymbolDatabase(); |
| 54 | for (const Scope * scope : symbolDatabase->functionScopes) { |
| 55 | for (const Token* tok = scope->bodyStart->next(); tok != scope->bodyEnd; tok = tok->next()) { |
| 56 | if (!tok->variable() || !tok->variable()->isPointer()) |
| 57 | continue; |
| 58 | const Token *str = tok->getValueTokenMinStrSize(mSettings); |
| 59 | if (!str) |
| 60 | continue; |
| 61 | if (Token::Match(tok, "%var% [") && Token::simpleMatch(tok->linkAt(1), "] =")) |
| 62 | stringLiteralWriteError(tok, str); |
| 63 | else if (Token::Match(tok->previous(), "* %var% =")) |
| 64 | stringLiteralWriteError(tok, str); |
| 65 | } |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | void CheckStringImpl::stringLiteralWriteError(const Token *tok, const Token *strValue) |
| 70 | { |
no test coverage detected