| 316 | } |
| 317 | |
| 318 | void ErrorMessage::deserialize(const std::string &data) |
| 319 | { |
| 320 | // TODO: clear all fields |
| 321 | certainty = Certainty::normal; |
| 322 | callStack.clear(); |
| 323 | |
| 324 | std::istringstream iss(data); |
| 325 | std::array<std::string, 10> results; |
| 326 | std::size_t elem = 0; |
| 327 | while (iss.good() && elem < 10) { |
| 328 | unsigned int len = 0; |
| 329 | if (!(iss >> len)) |
| 330 | throw InternalError(nullptr, "Internal Error: Deserialization of error message failed - invalid length"); |
| 331 | |
| 332 | if (iss.get() != ' ') |
| 333 | throw InternalError(nullptr, "Internal Error: Deserialization of error message failed - invalid separator"); |
| 334 | |
| 335 | if (!iss.good()) |
| 336 | throw InternalError(nullptr, "Internal Error: Deserialization of error message failed - premature end of data"); |
| 337 | |
| 338 | std::string temp; |
| 339 | if (len > 0) { |
| 340 | temp.resize(len); |
| 341 | iss.read(&temp[0], len); |
| 342 | |
| 343 | if (!iss.good()) |
| 344 | throw InternalError(nullptr, "Internal Error: Deserialization of error message failed - premature end of data"); |
| 345 | } |
| 346 | |
| 347 | results[elem++] = std::move(temp); |
| 348 | } |
| 349 | |
| 350 | if (!iss.good()) |
| 351 | throw InternalError(nullptr, "Internal Error: Deserialization of error message failed - premature end of data"); |
| 352 | |
| 353 | if (elem != 10) |
| 354 | throw InternalError(nullptr, "Internal Error: Deserialization of error message failed - insufficient elements"); |
| 355 | |
| 356 | id = std::move(results[0]); |
| 357 | severity = severityFromString(results[1]); |
| 358 | cwe.id = 0; |
| 359 | if (!results[2].empty()) { |
| 360 | std::string err; |
| 361 | if (!strToInt(results[2], cwe.id, &err)) |
| 362 | throw InternalError(nullptr, "Internal Error: Deserialization of error message failed - invalid CWE ID - " + err); |
| 363 | } |
| 364 | hash = 0; |
| 365 | if (!results[3].empty()) { |
| 366 | std::string err; |
| 367 | if (!strToInt(results[3], hash, &err)) |
| 368 | throw InternalError(nullptr, "Internal Error: Deserialization of error message failed - invalid hash - " + err); |
| 369 | } |
| 370 | remark = std::move(results[4]); |
| 371 | file0 = std::move(results[5]); |
| 372 | if (results[6] == "1") |
| 373 | certainty = Certainty::inconclusive; |
| 374 | mShortMessage = std::move(results[7]); |
| 375 | mVerboseMessage = std::move(results[8]); |