mirror of
https://github.com/azerothcore/azerothcore-wotlk.git
synced 2025-12-06 02:30:26 -08:00
feat(Core): Added ABORT() macro to prevent the usage of ASSERT(false) as a quick hack to crash the core misusing assert (#2273)
This commit is contained in:
parent
58f3cfe387
commit
854b426978
28 changed files with 127 additions and 74 deletions
|
|
@ -6,26 +6,45 @@
|
|||
|
||||
#include "Errors.h"
|
||||
|
||||
#include <ace/Stack_Trace.h>
|
||||
#include <ace/OS_NS_unistd.h>
|
||||
#include <thread>
|
||||
#include <cstdlib>
|
||||
|
||||
namespace Trinity {
|
||||
|
||||
void Assert(char const* file, int line, char const* function, char const* message)
|
||||
{
|
||||
ACE_Stack_Trace st;
|
||||
fprintf(stderr, "\n%s:%i in %s ASSERTION FAILED:\n %s\n%s\n",
|
||||
file, line, function, message, st.c_str());
|
||||
fprintf(stderr, "\n%s:%i in %s ASSERTION FAILED:\n %s\n",
|
||||
file, line, function, message);
|
||||
*((volatile int*)NULL) = 0;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void Fatal(char const* file, int line, char const* function, char const* message)
|
||||
void Assert(char const* file, int line, char const* function, char const* message, char const* format, ...)
|
||||
{
|
||||
fprintf(stderr, "\n%s:%i in %s FATAL ERROR:\n %s\n",
|
||||
file, line, function, message);
|
||||
ACE_OS::sleep(10);
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
|
||||
fprintf(stderr, "\n%s:%i in %s ASSERTION FAILED:\n %s ", file, line, function, message);
|
||||
vfprintf(stderr, format, args);
|
||||
fprintf(stderr, "\n");
|
||||
fflush(stderr);
|
||||
|
||||
va_end(args);
|
||||
*((volatile int*)NULL) = 0;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void Fatal(char const* file, int line, char const* function, char const* message, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, message);
|
||||
|
||||
fprintf(stderr, "\n%s:%i in %s FATAL ERROR:\n ", file, line, function);
|
||||
vfprintf(stderr, message, args);
|
||||
fprintf(stderr, "\n");
|
||||
fflush(stderr);
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::seconds(10));
|
||||
*((volatile int*)NULL) = 0;
|
||||
exit(1);
|
||||
}
|
||||
|
|
@ -44,4 +63,20 @@ 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);
|
||||
*((volatile int*)NULL) = 0;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
void AbortHandler(int /*sigval*/)
|
||||
{
|
||||
// nothing useful to log here, no way to pass args
|
||||
*((volatile int*)NULL) = 0;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
} // namespace Trinity
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue