]> diplodocus.org Git - nmh/blobdiff - sbr/done.c
Fix invalid pointer arithmetic.
[nmh] / sbr / done.c
index e4efff3a0afa02578e07326b71fa3236a5889521..5f2bc8db78c5f01ecfe94f354e81ad8e7a8b3089 100644 (file)
@@ -1,5 +1,4 @@
-/*
- * done.c -- terminate the program
+/* done.c -- terminate the program
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -8,4 +7,26 @@
 
 #include <h/mh.h>
 
-void (*done) (int) NORETURN = exit;
+static void (*altexit)(int) NORETURN = exit;
+
+/* set_done changes the path of done() from exit(3), or back to exit(3).
+ * Anything else will work, but a standard-error warning will report the
+ * old non-exit() value has been trampled. */
+void
+set_done(void (*new)(int) NORETURN)
+{
+    generic_pointer gpo, gpn;
+
+    if (altexit != exit && new != exit) {
+        gpo.f = (void (*)(void))altexit;
+        gpn.f = (void (*)(void))new;
+        inform("altexit trampled: %p %p", gpo.v, gpn.v);
+    }
+    altexit = new;
+}
+
+void NORETURN
+done(int status)
+{
+    (*altexit)(status);
+}