Save errno before using sprintf, ifstream.

std::ifstream in libstdc++ contains a bug, where it sets errno to zero.
To work around it, we manually save the errno before using std::ifstream
in debugger check, and reset it after we are done.

We also preventively save errno before using sprintf.

Fixes #835
This commit is contained in:
Martin Hořeňovský
2017-03-06 21:51:22 +01:00
parent e95bf48445
commit 613e1466f9
4 changed files with 34 additions and 0 deletions

View File

@@ -9,6 +9,7 @@
#define TWOBLUECUBES_CATCH_REPORTER_BASES_HPP_INCLUDED
#include "../internal/catch_interfaces_reporter.h"
#include "../internal/catch_errno_guard.hpp"
#include <cstring>
#include <cfloat>
@@ -27,6 +28,9 @@ namespace Catch {
// + 1 for null terminator
const size_t maxDoubleSize = DBL_MAX_10_EXP + 1 + 1 + 3 + 1;
char buffer[maxDoubleSize];
// Save previous errno, to prevent sprintf from overwriting it
ErrnoGuard guard;
#ifdef _MSC_VER
sprintf_s(buffer, "%.3f", duration);
#else