Skip to content

Commit 7956ccd

Browse files

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

include/json/assertions.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#define CPPTL_JSON_ASSERTIONS_H_INCLUDED
88

99
#include <stdlib.h>
10+
#include <sstream>
1011

1112
#if !defined(JSON_IS_AMALGAMATION)
1213
#include "config.h"
@@ -16,26 +17,26 @@
1617
#include <stdexcept>
1718
#define JSON_ASSERT(condition) \
1819
assert(condition); // @todo <= change this into an exception throw
19-
#define JSON_FAIL_MESSAGE(message) throw std::runtime_error(message);
20+
#define JSON_FAIL_MESSAGE(message) do{std::ostringstream oss; oss << message; throw std::runtime_error(oss.str());}while(0)
21+
//#define JSON_FAIL_MESSAGE(message) throw std::runtime_error(message)
2022
#else // JSON_USE_EXCEPTION
2123
#define JSON_ASSERT(condition) assert(condition);
2224

2325
// The call to assert() will show the failure message in debug builds. In
24-
// release bugs we write to invalid memory in order to crash hard, so that a
25-
// debugger or crash reporter gets the chance to take over. We still call exit()
26-
// afterward in order to tell the compiler that this macro doesn't return.
26+
// release bugs we abort, for a core-dump or debugger.
2727
#define JSON_FAIL_MESSAGE(message) \
2828
{ \
29-
assert(false&& message); \
30-
strcpy(reinterpret_cast<char*>(666), message); \
31-
exit(123); \
29+
std::ostringstream oss; oss << message; \
30+
assert(false && oss.str().c_str()); \
31+
abort(); \
3232
}
3333

34+
3435
#endif
3536

3637
#define JSON_ASSERT_MESSAGE(condition, message) \
3738
if (!(condition)) { \
38-
JSON_FAIL_MESSAGE(message) \
39+
JSON_FAIL_MESSAGE(message); \
3940
}
4041

4142
#endif // CPPTL_JSON_ASSERTIONS_H_INCLUDED

0 commit comments

Comments
 (0)