From 0d5bf48cd63669e6c84c9c288f2b10a5b3b2bfdf Mon Sep 17 00:00:00 2001 From: tewk <tewk@unknown> Date: Mon, 15 Jul 2002 16:22:30 +0000 Subject: [PATCH] Added check for null length string to avoid sgementation fault --- src/common/log.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/common/log.c b/src/common/log.c index 509740a303c..2e2d883549e 100644 --- a/src/common/log.c +++ b/src/common/log.c @@ -321,7 +321,7 @@ static void log_msg(log_level_t level, const char *fmt, va_list args) if (level <= STDERR_LEVEL) { fflush(stdout); - if (buf[strlen(buf) - 1] == '\n') + if (strlen(buf) > 0 && buf[strlen(buf) - 1] == '\n') fprintf(stderr, "%s: %s%s", log->argv0, pfx, buf); else fprintf(stderr, "%s: %s%s\n", log->argv0, pfx, buf); @@ -331,7 +331,7 @@ static void log_msg(log_level_t level, const char *fmt, va_list args) if (level <= LOGFILE_LEVEL && log->logfp != NULL) { xstrfmtcat(&msgbuf, "[%T] %s%s", pfx, buf); - if (buf[strlen(buf) - 1] == '\n') + if (strlen(buf) > 0 && buf[strlen(buf) - 1] == '\n') fprintf(log->logfp, "%s", msgbuf); else fprintf(log->logfp, "%s\n", msgbuf); -- GitLab