verror_msg: don't printf(NULL)

This commit is contained in:
Denis Vlasenko 2007-05-29 21:41:28 +00:00
parent fe3e1776ad
commit 4ef7d3a2de

View File

@ -20,6 +20,9 @@ void bb_verror_msg(const char *s, va_list p, const char* strerr)
va_list p2; va_list p2;
va_copy(p2, p); va_copy(p2, p);
if (!s) /* nomsg[_and_die] uses NULL fmt */
s = ""; /* some libc don't like printf(NULL) */
if (logmode & LOGMODE_STDIO) { if (logmode & LOGMODE_STDIO) {
fflush(stdout); fflush(stdout);
fprintf(stderr, "%s: ", applet_name); fprintf(stderr, "%s: ", applet_name);
@ -28,7 +31,7 @@ void bb_verror_msg(const char *s, va_list p, const char* strerr)
fputs(msg_eol, stderr); fputs(msg_eol, stderr);
else else
fprintf(stderr, "%s%s%s", fprintf(stderr, "%s%s%s",
s ? ": " : "", s[0] ? ": " : "",
strerr, msg_eol); strerr, msg_eol);
} }
if (ENABLE_FEATURE_SYSLOG && (logmode & LOGMODE_SYSLOG)) { if (ENABLE_FEATURE_SYSLOG && (logmode & LOGMODE_SYSLOG)) {
@ -36,8 +39,10 @@ void bb_verror_msg(const char *s, va_list p, const char* strerr)
vsyslog(LOG_ERR, s, p2); vsyslog(LOG_ERR, s, p2);
else { else {
char *msg; char *msg;
if (vasprintf(&msg, s, p2) < 0) if (vasprintf(&msg, s, p2) < 0) {
bb_error_msg_and_die(bb_msg_memory_exhausted); fprintf(stderr, "%s: %s\n", applet_name, bb_msg_memory_exhausted);
xfunc_die();
}
syslog(LOG_ERR, "%s: %s", msg, strerr); syslog(LOG_ERR, "%s: %s", msg, strerr);
free(msg); free(msg);
} }