|
23 | 23 | #include "path.h" |
24 | 24 | #include "settings.h" |
25 | 25 | #include "suppressions.h" |
| 26 | +#include "symboldatabase.h" |
26 | 27 | #include "token.h" |
27 | 28 | #include "tokenlist.h" |
28 | 29 | #include "utils.h" |
|
35 | 36 | #include <cstring> |
36 | 37 | #include <fstream> |
37 | 38 | #include <iomanip> |
| 39 | +#include <numeric> |
38 | 40 | #include <sstream> |
39 | 41 | #include <string> |
40 | 42 | #include <unordered_map> |
@@ -161,11 +163,12 @@ ErrorMessage::ErrorMessage(ErrorPath errorPath, const TokenList *tokenList, Seve |
161 | 163 |
|
162 | 164 | setmsg(msg); |
163 | 165 |
|
164 | | - std::list<const Token*> callstack; |
165 | | - for (const ErrorPathItem& e: errorPath) { |
166 | | - callstack.push_back(e.first); |
167 | | - } |
168 | | - calculateWarningHash(callstack); |
| 166 | + std::list<const Token*> tokens; |
| 167 | + std::transform(errorPath.cbegin(), errorPath.cend(), std::back_inserter(tokens), |
| 168 | + [](const ErrorPathItem& e) { |
| 169 | + return e.first; |
| 170 | + }); |
| 171 | + calculateWarningHash(tokens); |
169 | 172 | } |
170 | 173 |
|
171 | 174 | // TODO: improve errorhandling? |
@@ -259,6 +262,8 @@ void ErrorMessage::calculateWarningHash(const std::list<const Token*>& callstack |
259 | 262 | for (const Token* tok: callstack) { |
260 | 263 | if (!tok) |
261 | 264 | continue; |
| 265 | + if (!tok->scope()) |
| 266 | + return; // might be a syntax error before scope info has been set |
262 | 267 | if (tok->scope()->isExecutable()) { |
263 | 268 | // Executable scope => include all tokens in the function => if the |
264 | 269 | // function is changed the hash is changed |
@@ -295,10 +300,9 @@ void ErrorMessage::calculateWarningHash(const std::list<const Token*>& callstack |
295 | 300 |
|
296 | 301 | // hash algorithm: sdbm |
297 | 302 | // any hash algorithm can be used but it has to be the same hash on different platforms and compilers |
298 | | - hash = 0; |
299 | | - for (auto c: hashString) { |
300 | | - hash = c + (hash << 6) + (hash << 16) - hash; |
301 | | - } |
| 303 | + hash = std::accumulate(hashString.cbegin(), hashString.cend(), 0, [](std::size_t hash, char c) { |
| 304 | + return static_cast<unsigned char>(c) + (hash << 6) + (hash << 16) - hash; |
| 305 | + }); |
302 | 306 | } |
303 | 307 |
|
304 | 308 | static void serializeString(std::string &oss, const std::string & str) |
|
0 commit comments