X-Git-Url: https://plomlompom.com/repos/foo.html?a=blobdiff_plain;f=src%2Fcommon%2Frexit.c;h=7eeaccb52d1c92d91a3c9760771888de70b16bde;hb=814778ca9bf76eeaf0520b7551103e818a9775d8;hp=facf63fffc71a53a9ffd9c0581383f9954bde4f1;hpb=f6445615b0b81a83ef75cc4774bac992bac234bb;p=plomrogue
diff --git a/src/common/rexit.c b/src/common/rexit.c
index facf63f..7eeaccb 100644
--- a/src/common/rexit.c
+++ b/src/common/rexit.c
@@ -1,11 +1,17 @@
-/* src/common/rexit.c */
+/* src/common/rexit.c
+ *
+ * This file is part of PlomRogue. PlomRogue is licensed under the GPL version 3
+ * or any later version. For details on its copyright, license, and warranties,
+ * see the file NOTICE in the root directory of the PlomRogue source package.
+ */
#include "rexit.h"
#include /* global errno */
#include /* uint16_t */
#include /* printf(), perror(), sprintf() */
-#include /* exit(), EXIT_FAILURE */
+#include /* exit(), free(), EXIT_FAILURE */
#include /* strlen() */
+#include "try_malloc.h" /* try_malloc() */
@@ -20,14 +26,14 @@ extern void set_cleanup_func(void (* f)())
-extern void exit_err(int err, char * msg)
+extern void exit_err(int err, const char * msg)
{
if (0 == err)
{
return;
}
cleanup_func();
- if (NULL == msg)
+ if (!msg)
{
msg = "Details unknown.";
}
@@ -41,14 +47,16 @@ extern void exit_err(int err, char * msg)
-extern void exit_trouble(int err, char * parent, char * child)
+extern void exit_trouble(int err, const char * parent, const char * child)
{
char * p1 = "Trouble in ";
char * p2 = " with ";
char * p3 = ".";
uint16_t size = strlen(p1) + strlen(parent) + strlen(p2) + strlen(child)
+ strlen(p3) + 1;
- char msg[size];
- sprintf(msg, "%s%s%s%s%s", p1, parent, p2, child, p3);
+ char * msg = try_malloc(size, __func__);
+ int test = sprintf(msg, "%s%s%s%s%s", p1, parent, p2, child, p3);
+ exit_err(test < 0, "Trouble in exit_trouble with sprintf.");
exit_err(err, msg);
+ free(msg);
}