home
·
contact
·
privacy
projects
/
plomrogue
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Remove redundant uses of NULL.
[plomrogue]
/
src
/
common
/
rexit.c
diff --git
a/src/common/rexit.c
b/src/common/rexit.c
index 7b837e946987bc59b658ba441f5129b1c22a1c7a..b528975290ae7eaf78f9dcd6027b9be4afeefd4b 100644
(file)
--- a/
src/common/rexit.c
+++ b/
src/common/rexit.c
@@
-4,8
+4,9
@@
#include <errno.h> /* global errno */
#include <stdint.h> /* uint16_t */
#include <stdio.h> /* printf(), perror(), sprintf() */
#include <errno.h> /* global errno */
#include <stdint.h> /* uint16_t */
#include <stdio.h> /* printf(), perror(), sprintf() */
-#include <stdlib.h> /* exit(), EXIT_FAILURE */
+#include <stdlib.h> /* exit(),
free(),
EXIT_FAILURE */
#include <string.h> /* strlen() */
#include <string.h> /* strlen() */
+#include "try_malloc.h" /* try_malloc() */
@@
-20,20
+21,18
@@
extern void set_cleanup_func(void (* f)())
-extern void exit_err(int err, char * msg)
+extern void exit_err(int err, c
onst c
har * msg)
{
if (0 == err)
{
return;
}
cleanup_func();
{
if (0 == err)
{
return;
}
cleanup_func();
- if (
NULL ==
msg)
+ if (
!
msg)
{
msg = "Details unknown.";
}
{
msg = "Details unknown.";
}
- printf("Aborted program due to error. %s\n"
- "Internal error code: %d\n",
- msg, err);
+ printf("Aborted program due to error. %s\n", msg);
if (0 != errno)
{
perror("errno states");
if (0 != errno)
{
perror("errno states");
@@
-43,14
+42,16
@@
extern void exit_err(int err, char * msg)
-extern void exit_trouble(int err, c
har * parent,
char * child)
+extern void exit_trouble(int err, c
onst 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 * 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);
exit_err(err, msg);
+ free(msg);
}
}