]> git.refcnt.org Git - colorize.git/blobdiff - colorize.c
Terminate buffer with single NUL
[colorize.git] / colorize.c
index 3b25357a9fab37665273a0374a8b79bd3e298390..16094c6e673c3e51eb33629a226700df0dfc62ed 100644 (file)
@@ -2,7 +2,7 @@
  * colorize - Read text from standard input stream or file and print
  *            it colorized through use of ANSI escape sequences
  *
- * Copyright (c) 2011-2015 Steven Schubiger
+ * Copyright (c) 2011-2016 Steven Schubiger
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
 
 #define DEBUG_FILE "debug.txt"
 
-#define VERSION "0.57"
+#define VERSION "0.58"
 
 typedef enum { false, true } bool;
 
@@ -745,10 +745,10 @@ read_print_stream (bool bold, const struct color **colors, const char *file, FIL
         size_t bytes_read;
         char *eol;
         const char *line;
-        memset (buf, '\0', BUF_SIZE + 1);
         bytes_read = fread (buf, 1, BUF_SIZE, stream);
         if (bytes_read != BUF_SIZE && ferror (stream))
           vfprintf_fail (formats[FMT_ERROR], BUF_SIZE, "read");
+        buf[bytes_read] = '\0';
         line = buf;
         while ((eol = strpbrk (line, "\n\r")))
           {