From: Simon Ruderich Date: Mon, 3 Jun 2013 02:32:12 +0000 (+0200) Subject: debug.h: Handle overflow in debug(). X-Git-Tag: 0.1~119 X-Git-Url: https://ruderich.org/simon/gitweb/?a=commitdiff_plain;h=66fb589680db241e916b7f7f43d9e6058dcdb571;p=coloredstderr%2Fcoloredstderr.git debug.h: Handle overflow in debug(). --- diff --git a/src/debug.h b/src/debug.h index 6456898..4dab03c 100644 --- a/src/debug.h +++ b/src/debug.h @@ -33,6 +33,10 @@ static void debug(const char *format, ...) { 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");