| 679 | } |
| 680 | |
| 681 | static size_t dumpLocalDebugSyncLog(unsigned logIndex) |
| 682 | { |
| 683 | if (debugSyncTmpBuf.size() < targetDebugSyncTmpBufSize) |
| 684 | { |
| 685 | debugSyncTmpBuf.clear(); |
| 686 | debugSyncTmpBuf.resize(targetDebugSyncTmpBufSize); |
| 687 | } |
| 688 | const size_t bufSizeLimit = debugSyncTmpBuf.size(); |
| 689 | size_t bufIndex = 0; |
| 690 | auto enforceLimit = [&bufIndex, &bufSizeLimit]() { |
| 691 | if (bufIndex > bufSizeLimit) |
| 692 | { |
| 693 | bufIndex = bufSizeLimit; |
| 694 | // grow buffer slightly for next debug sync log send (up to max) |
| 695 | targetDebugSyncTmpBufSize = std::min<size_t>(targetDebugSyncTmpBufSize + 500000, kMaxDebugSyncBufferSize); |
| 696 | } |
| 697 | }; |
| 698 | // Dump our version, and also erase it, so we only dump it at most once. |
| 699 | bufIndex += snprintf((char*)debugSyncTmpBuf.data() + bufIndex, bufSizeLimit - bufIndex, "===== BEGIN gameTime=%u, %zu entries, CRC 0x%08X =====\n", syncDebugLog[logIndex].getGameTime(), syncDebugLog[logIndex].getNumEntries(), syncDebugLog[logIndex].getCrc()); |
| 700 | enforceLimit(); // snprintf will not overflow debugSyncTmpBuf, but returns as much as it would have printed if possible. |
| 701 | bufIndex += syncDebugLog[logIndex].snprint((char*)debugSyncTmpBuf.data() + bufIndex, bufSizeLimit - bufIndex); |
| 702 | enforceLimit(); // snprintf will not overflow debugSyncTmpBuf, but returns as much as it would have printed if possible. |
| 703 | bufIndex += snprintf((char*)debugSyncTmpBuf.data() + bufIndex, bufSizeLimit - bufIndex, "===== END gameTime=%u, %zu entries, CRC 0x%08X =====\n", syncDebugLog[logIndex].getGameTime(), syncDebugLog[logIndex].getNumEntries(), syncDebugLog[logIndex].getCrc()); |
| 704 | enforceLimit(); // snprintf will not overflow debugSyncTmpBuf, but returns as much as it would have printed if possible. |
| 705 | |
| 706 | return bufIndex; |
| 707 | } |
| 708 | |
| 709 | static size_t dumpLocalDebugSyncLogByTime(uint32_t time) |
| 710 | { |
no test coverage detected