home
·
contact
·
privacy
projects
/
plomrogue
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Test return values of _all_ *printf() calls.
[plomrogue]
/
src
/
common
/
rexit.c
diff --git
a/src/common/rexit.c
b/src/common/rexit.c
index 7b837e946987bc59b658ba441f5129b1c22a1c7a..7e16f12f7c8bce1aeed17635c9f73ef8f963a8c1 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() */
@@
-31,9
+32,7
@@
extern void exit_err(int err, char * 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");
@@
-45,12
+44,15
@@
extern void exit_err(int err, char * msg)
extern void exit_trouble(int err, char * parent, char * child)
{
extern void exit_trouble(int err, char * parent, char * child)
{
+ char * f_name = "exit_trouble()";
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, f_name);
+ 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);
}
}