From: Vsevolod Stakhov Date: Wed, 23 Apr 2014 12:29:48 +0000 (+0100) Subject: Fix issue with printing empty strings. X-Git-Tag: 0.7.0~283 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=3c31e3680e05ea7a449691956ff8c7c424eb9521;p=rspamd.git Fix issue with printing empty strings. --- diff --git a/src/libutil/printf.c b/src/libutil/printf.c index 0c4c8f03d..195c04520 100644 --- a/src/libutil/printf.c +++ b/src/libutil/printf.c @@ -197,8 +197,12 @@ static glong rspamd_printf_append_file (const gchar *buf, glong buflen, gpointer ud) { FILE *dst = (FILE *)ud; - - return fwrite (buf, 1, buflen, dst); + if (buflen > 0) { + return fwrite (buf, 1, buflen, dst); + } + else { + return 0; + } } static glong @@ -206,7 +210,9 @@ rspamd_printf_append_gstring (const gchar *buf, glong buflen, gpointer ud) { GString *dst = (GString *)ud; - g_string_append_len (dst, buf, buflen); + if (buflen > 0) { + g_string_append_len (dst, buf, buflen); + } return buflen; } @@ -296,7 +302,7 @@ rspamd_printf_gstring (GString *s, const gchar *fmt, ...) #define RSPAMD_PRINTF_APPEND(buf, len) \ do { \ wr = func ((buf), (len), apd); \ - if (wr <= 0) { \ + if (wr < (__typeof(wr))(len)) { \ goto oob; \ } \ written += wr; \ @@ -439,7 +445,6 @@ rspamd_vprintf_common (rspamd_printf_append_func func, gpointer apd, const gchar /* NULL terminated string */ slen = strlen (p); } - RSPAMD_PRINTF_APPEND (p, slen); continue;