X-Git-Url: https://ruderich.org/simon/gitweb/?a=blobdiff_plain;f=src%2Fdebug.h;h=3c6553e2248b49650c0d926a0c2100d9f57f7edb;hb=f54cd101d750cb31f54081a41d6cb880a9199dba;hp=7425ce475f8c49f475f4dba01d48408ee65f547b;hpb=dfd317650f05542db49d7bc37649a232f28efa3f;p=coloredstderr%2Fcoloredstderr.git diff --git a/src/debug.h b/src/debug.h index 7425ce4..3c6553e 100644 --- a/src/debug.h +++ b/src/debug.h @@ -1,7 +1,7 @@ /* * Debug functions. * - * Copyright (C) 2013 Simon Ruderich + * Copyright (C) 2013-2014 Simon Ruderich * * 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 @@ -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; } @@ -34,13 +36,14 @@ static void debug_write(int fd, int first_call, char const *format, va_list ap) DLSYM_FUNCTION(real_close, "close"); if (first_call) { - char nl = '\n'; + char const nl = '\n'; real_write(fd, &nl, 1); } real_write(fd, buffer, (size_t)written); 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;