X-Git-Url: https://ruderich.org/simon/gitweb/?a=blobdiff_plain;f=src%2Fdebug.h;h=1a45c0f993b5a402fe69ba4e5fd044d4742fa6b7;hb=51377106d1bd632546fa66bc27ac1a02a647f026;hp=6456898cb7e601bb6fe987e3e4f6a39831f154cd;hpb=abc3d7889f3774717baf5795ffab2efb396d2570;p=coloredstderr%2Fcoloredstderr.git diff --git a/src/debug.h b/src/debug.h index 6456898..1a45c0f 100644 --- a/src/debug.h +++ b/src/debug.h @@ -26,13 +26,18 @@ static void debug(const char *format, ...) { /* If the file doesn't exist, do nothing. Prevents writing log files in * unexpected places. The user must create the file manually. */ int fd = open(DEBUG_FILE, O_WRONLY | O_APPEND); - if (fd == -1) + if (fd == -1) { return; + } va_list ap; va_start(ap, format); int written = vsnprintf(buffer, sizeof(buffer), format, ap); va_end(ap); + /* Overflow. */ + if ((size_t)written >= sizeof(buffer)) { + written = sizeof(buffer) - 1; + } /* Make sure these functions are loaded. */ DLSYM_FUNCTION(real_write, "write");