Issue 17 - patch by tilman2: Always pass a format string to syslog()
[umurmur.git] / src / log.c
index 94f86a822503dda3bd18ed0aaab3661ee1b65d46..5d2af2b8bf295e2b80f1fc0c7c6dfcdd540c8563 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -58,55 +58,52 @@ void Log_free()
 void logthis(const char *logstring, ...)
 {
        va_list argp;
-       char buf[STRSIZE + 2];
+       char buf[STRSIZE + 1];
        
        va_start(argp, logstring);
        vsnprintf(&buf[0], STRSIZE, logstring, argp);
        va_end(argp);
-       strcat(buf, "\n");
        if (termprint)
-               fprintf(stderr, "%s", buf);
+               fprintf(stderr, "%s\n", buf);
        else
-               syslog(LOG_INFO, buf);
+               syslog(LOG_INFO, "%s", buf);
 }
 
 void Log_warn(const char *logstring, ...)
 {
        va_list argp;
-       char buf[STRSIZE + 2];
+       char buf[STRSIZE + 1];
        int offset = 0;
        
        va_start(argp, logstring);
        offset = sprintf(buf, "WARN: ");
        vsnprintf(&buf[offset], STRSIZE - offset, logstring, argp);
        va_end(argp);
-       strcat(buf, "\n");
        if (termprint)
-               fprintf(stderr, "%s", buf);
+               fprintf(stderr, "%s\n", buf);
        else
-               syslog(LOG_WARNING, buf);
+               syslog(LOG_WARNING, "%s", buf);
 }
 
 void Log_info(const char *logstring, ...)
 {
        va_list argp;
-       char buf[STRSIZE + 2];
+       char buf[STRSIZE + 1];
        int offset = 0;
        
        va_start(argp, logstring);
        offset = sprintf(buf, "INFO: ");
        vsnprintf(&buf[offset], STRSIZE - offset, logstring, argp);
        va_end(argp);
-       strcat(buf, "\n");
        if (termprint)
-               fprintf(stderr, "%s", buf);
+               fprintf(stderr, "%s\n", buf);
        else
-               syslog(LOG_INFO, buf);
+               syslog(LOG_INFO, "%s", buf);
 }
 void Log_info_client(client_t *client, const char *logstring, ...)
 {
        va_list argp;
-       char buf[STRSIZE + 2];
+       char buf[STRSIZE + 1];
        int offset = 0;
        
        va_start(argp, logstring);
@@ -118,11 +115,10 @@ void Log_info_client(client_t *client, const char *logstring, ...)
                                           client->username == NULL ? "" : client->username,
                                           inet_ntoa(client->remote_tcp.sin_addr),
                                           ntohs(client->remote_tcp.sin_port));
-       strcat(buf, "\n");
        if (termprint)
-               fprintf(stderr, "%s", buf);
+               fprintf(stderr, "%s\n", buf);
        else
-               syslog(LOG_INFO, buf);
+               syslog(LOG_INFO, "%s", buf);
        
 }
 
@@ -130,34 +126,32 @@ void Log_info_client(client_t *client, const char *logstring, ...)
 void Log_debug(const char *logstring, ...)
 {
        va_list argp;
-       char buf[STRSIZE + 2];
+       char buf[STRSIZE + 1];
        int offset = 0;
        
        va_start(argp, logstring);
        offset = sprintf(buf, "DEBUG: ");
        vsnprintf(&buf[offset], STRSIZE - offset, logstring, argp);
        va_end(argp);
-       strcat(buf, "\n");
        if (termprint)
-               fprintf(stderr, "%s", buf);
+               fprintf(stderr, "%s\n", buf);
        else
-               syslog(LOG_DEBUG, buf);
+               syslog(LOG_DEBUG, "%s", buf);
 }
 #endif
 
 void Log_fatal(const char *logstring, ...)
 {
        va_list argp;
-       char buf[STRSIZE + 2];
+       char buf[STRSIZE + 1];
        int offset = 0;
        va_start(argp, logstring);
        offset = sprintf(buf, "FATAL: ");
        vsnprintf(&buf[offset], STRSIZE - offset, logstring, argp);
        va_end(argp);
-       strcat(buf, "\n");
        if (termprint)
-               fprintf(stderr, "%s", buf);
+               fprintf(stderr, "%s\n", buf);
        else
-               syslog(LOG_CRIT, buf);
+               syslog(LOG_CRIT, "%s", buf);
        exit(1);
 }