Captured std::clog output corruption (0x00's appear)
- Dominant language
- C++
- Stars
- 21.5k
- Forks
- 3.5k
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 2
Description
**Describe the bug**
My code under test has a fallback log handling function like this:
```
static void fallback_log_func(int domain, int level, const char* msg, ...)
{
std::clog << "[domain"<< domain << "]" << msg << std::endl;
}
```
And in some cases it gets the output of an temporary string:
```
auto s = os.str(); // os is std::ostringstream
if (s.size > max_len) s.resize(max_len);
log.handler(lh.ranid, level, s.c_str());
```
Sometimes, in the recorded `std::cerr` I find strings of zeros (as "0x00") inserted or replacing parts of the legit output.
I tried replacing `std::clog` with `ffprintf`, things work as expected, apparently:
```
static void fallback_log_func(int domain, int level, const char* msg, ...)
{
fprintf(stderr, "[domain%d]%s\n", domain, msg); fflush(stderr);
}
```
**Platform information:**
- OS: **Ubuntu 18.04**
- Compiler+version: **GCC v7.5.0**
- Catch version: **v2.13.0**
**Additional context**
It does not happen consistently.
Running mostly inside Visual Studio Code with "C++ TestMate" extension which probably relies on junit output.
But I am pretty sure I have seen long strings of 0x00's also in terminal output (non junit).
Contributor guide
Research direction
No Catch2 file or test is named. Start by reproducing the report's fallback_log_func and temporary std::ostringstream path on Ubuntu 18.04 with GCC 7.5.0, comparing VS Code/C++ TestMate output with terminal output. Done means the intermittent 0x00 corruption is reproduced, its capture path is identified, and a regression test demonstrates correct recorded output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100