aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/sanity.cpp
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2015-07-24 00:50:58 -0700
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2015-07-24 00:59:27 -0700
commitb4f53143b0e05fd3061cdf2e65e17a6a2904090b (patch)
tree4785bf31f7b89fc2420aa740d9a6967dc6c6f9b1 /src/sanity.cpp
parent9c2fdc6da57032c4448b59de5872086eea626b74 (diff)
Migrate source files into src/ directory
This change moves source files into a src/ directory, and puts object files into an obj/ directory. The Makefile and xcode project are updated accordingly. Fixes #1866
Diffstat (limited to 'src/sanity.cpp')
-rw-r--r--src/sanity.cpp76
1 files changed, 76 insertions, 0 deletions
diff --git a/src/sanity.cpp b/src/sanity.cpp
new file mode 100644
index 00000000..f8976941
--- /dev/null
+++ b/src/sanity.cpp
@@ -0,0 +1,76 @@
+/** \file sanity.c
+ Functions for performing sanity checks on the program state
+*/
+#include "config.h"
+
+#include <stdlib.h>
+#include <wchar.h>
+#include <stdio.h>
+#include <errno.h>
+#include <termios.h>
+#include <unistd.h>
+#include <signal.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <dirent.h>
+
+
+#include "fallback.h"
+#include "util.h"
+
+#include "common.h"
+#include "sanity.h"
+#include "proc.h"
+#include "history.h"
+#include "reader.h"
+#include "kill.h"
+#include "wutil.h"
+
+
+/**
+ Status from earlier sanity checks
+*/
+static int insane;
+
+void sanity_lose()
+{
+ debug(0, _(L"Errors detected, shutting down. Break on sanity_lose() to debug."));
+ insane = 1;
+}
+
+int sanity_check()
+{
+ if (!insane)
+ if (get_is_interactive())
+ history_sanity_check();
+ if (!insane)
+ reader_sanity_check();
+ if (!insane)
+ kill_sanity_check();
+ if (!insane)
+ proc_sanity_check();
+
+ return insane;
+}
+
+void validate_pointer(const void *ptr, const wchar_t *err, int null_ok)
+{
+
+ /*
+ Test if the pointer data crosses a segment boundary.
+ */
+
+ if ((0x00000003l & (intptr_t)ptr) != 0)
+ {
+ debug(0, _(L"The pointer '%ls' is invalid"), err);
+ sanity_lose();
+ }
+
+ if ((!null_ok) && (ptr==0))
+ {
+ debug(0, _(L"The pointer '%ls' is null"), err);
+ sanity_lose();
+ }
+}
+
+