]> ruderich.org/simon Gitweb - coloredstderr/coloredstderr.git/blobdiff - src/debug.h
Add more error checks.
[coloredstderr/coloredstderr.git] / src / debug.h
index 7425ce475f8c49f475f4dba01d48408ee65f547b..5e5cc6d937ef55e7e73de1f62310183daa40bb8a 100644 (file)
@@ -24,8 +24,10 @@ static void debug_write(int fd, int first_call, char const *format, va_list ap)
     char buffer[1024];
 
     int written = vsnprintf(buffer, sizeof(buffer), format, ap);
+    if (written < 0) {
+        return; /* shouldn't happen */
     /* Overflow. */
-    if ((size_t)written >= sizeof(buffer)) {
+    } else if ((size_t)written >= sizeof(buffer)) {
         written = sizeof(buffer) - 1;
     }
 
@@ -41,6 +43,7 @@ static void debug_write(int fd, int first_call, char const *format, va_list ap)
     real_close(fd);
 }
 
+#ifdef DEBUG
 static void debug(char const *format, ...) {
     va_list ap;
 
@@ -63,6 +66,7 @@ static void debug(char const *format, ...) {
 
     errno = saved_errno;
 }
+#endif
 
 static void warning(char const *format, ...) {
     va_list ap;