Core: Added ABORT() macro to prevent the usage of ASSERT(false) as a quick hack to crash the core misusing assert

This commit is contained in:
StormBytePP committed 2015-09-21 15:11:06 +02:00
1 parent ff71da2b05
commit 7b245a0b6b
23 files changed
+62 -55

No files matched your search

+11 -8
View File
@@ -29,8 +29,7 @@ void Assert(char const* file, int line, char const* function, char const* messag
{
fprintf(stderr, "\n%s:%i in %s ASSERTION FAILED:\n %s\n",
file, line, function, message);
*((volatile int*)NULL) = 0;
exit(1);
abort();
}
void Assert(char const* file, int line, char const* function, char const* message, char const* format, ...)
@@ -44,8 +43,7 @@ void Assert(char const* file, int line, char const* function, char const* messag
fflush(stderr);
va_end(args);
*((volatile int*)NULL) = 0;
exit(1);
abort();
}
void Fatal(char const* file, int line, char const* function, char const* message)
@@ -54,16 +52,14 @@ void Fatal(char const* file, int line, char const* function, char const* message
file, line, function, message);
std::this_thread::sleep_for(std::chrono::seconds(10));
*((volatile int*)NULL) = 0;
exit(1);
abort();
}
void Error(char const* file, int line, char const* function, char const* message)
{
fprintf(stderr, "\n%s:%i in %s ERROR:\n %s\n",
file, line, function, message);
*((volatile int*)NULL) = 0;
exit(1);
abort();
}
void Warning(char const* file, int line, char const* function, char const* message)
@@ -72,4 +68,11 @@ void Warning(char const* file, int line, char const* function, char const* messa
file, line, function, message);
}
void Abort(char const* file, int line, char const* function)
{
fprintf(stderr, "\n%s:%i in %s ABORTED\n",
file, line, function);
abort();
}
} // namespace Trinity
+4
View File
@@ -29,6 +29,8 @@ namespace Trinity
DECLSPEC_NORETURN void Fatal(char const* file, int line, char const* function, char const* message) ATTR_NORETURN;
DECLSPEC_NORETURN void Error(char const* file, int line, char const* function, char const* message) ATTR_NORETURN;
DECLSPEC_NORETURN void Abort(char const* file, int line, char const* function) ATTR_NORETURN;
void Warning(char const* file, int line, char const* function, char const* message);
@@ -46,8 +48,10 @@ namespace Trinity
#define WPFatal(cond, msg) ASSERT_BEGIN do { if (!(cond)) Trinity::Fatal(__FILE__, __LINE__, __FUNCTION__, (msg)); } while(0) ASSERT_END
#define WPError(cond, msg) ASSERT_BEGIN do { if (!(cond)) Trinity::Error(__FILE__, __LINE__, __FUNCTION__, (msg)); } while(0) ASSERT_END
#define WPWarning(cond, msg) ASSERT_BEGIN do { if (!(cond)) Trinity::Warning(__FILE__, __LINE__, __FUNCTION__, (msg)); } while(0) ASSERT_END
#define WPAbort() ASSERT_BEGIN do { Trinity::Abort(__FILE__, __LINE__, __FUNCTION__); } while(0) ASSERT_END
#define ASSERT WPAssert
#define ABORT WPAbort
template <typename T> inline T* ASSERT_NOTNULL(T* pointer)
{