]> err.no Git - util-linux/commitdiff
snprintf always NULL terminates
authorLaMont Jones <lamont@mmjgroup.com>
Tue, 31 Jul 2007 05:01:29 +0000 (23:01 -0600)
committerLaMont Jones <lamont@mmjgroup.com>
Tue, 31 Jul 2007 05:01:29 +0000 (23:01 -0600)
misc-utils/logger.c

index 49ba5dc7c823a46247f3776b248a55d7df9db50f..9a7cb05881f92e523d7738b6ff461af366671be1 100644 (file)
@@ -89,10 +89,9 @@ mysyslog(int fd, int logflags, int pri, char *tag, char *msg) {
        time_t now;
 
        if (fd > -1) {
-               if (logflags & LOG_PID) {
-                       snprintf (pid, sizeof(pid)-1, "[%d]", getpid());
-                      pid[sizeof(pid)-1]=0;
-              } else
+               if (logflags & LOG_PID)
+                       snprintf (pid, sizeof(pid), "[%d]", getpid());
+              else
                       pid[0] = 0;
                if (tag)
                       cp = tag;
@@ -104,9 +103,8 @@ mysyslog(int fd, int logflags, int pri, char *tag, char *msg) {
                (void)time(&now);
               tp = ctime(&now)+4;
 
-               snprintf(buf, sizeof(buf)-1, "<%d>%.15s %.200s%s: %.400s",
+               snprintf(buf, sizeof(buf), "<%d>%.15s %.200s%s: %.400s",
                        pri, tp, cp, pid, msg);
-              buf[sizeof(buf)-1]=0;
 
                if (write(fd, buf, strlen(buf)+1) < 0)
                        return; /* error */