aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-08-31 15:33:58 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-08-31 15:33:58 +0100
commitafb5308643e8c0c822b96df03d5a0b69a96c6d37 (patch)
treebcb0b17ced8a9325ae7a98963cd0bd3ad2527bcb /src
parente1e520569a44a8ebbdc30f2165497183903e5fa3 (diff)
downloadrspamd-afb5308643e8c0c822b96df03d5a0b69a96c6d37.tar.gz
rspamd-afb5308643e8c0c822b96df03d5a0b69a96c6d37.zip
[Minor] Tune printf for hex and base32 input strings
Diffstat (limited to 'src')
-rw-r--r--src/libutil/printf.c43
1 files changed, 33 insertions, 10 deletions
diff --git a/src/libutil/printf.c b/src/libutil/printf.c
index 10dc899ba..db21346ea 100644
--- a/src/libutil/printf.c
+++ b/src/libutil/printf.c
@@ -579,28 +579,42 @@ rspamd_vprintf_common (rspamd_printf_append_func func,
p = "(NULL)";
}
- if (slen == -1) {
- /* NULL terminated string */
- slen = strlen (p);
- }
-
- if (G_UNLIKELY (width != 0)) {
- slen = MIN (slen, width);
- }
-
if (G_UNLIKELY (b32)) {
gchar *b32buf;
+ if (G_UNLIKELY (slen == -1)) {
+ if (G_LIKELY (width != 0)) {
+ slen = width;
+ }
+ else {
+ /* NULL terminated string */
+ slen = strlen (p);
+ }
+ }
+
b32buf = rspamd_encode_base32 (p, slen);
if (b32buf) {
RSPAMD_PRINTF_APPEND (b32buf, strlen (b32buf));
g_free (b32buf);
}
+ else {
+ RSPAMD_PRINTF_APPEND ("(NULL)", sizeof ("(NULL)") - 1);
+ }
}
else if (G_UNLIKELY (hex)) {
gchar hexbuf[2];
+ if (G_UNLIKELY (slen == -1)) {
+ if (G_LIKELY (width != 0)) {
+ slen = width;
+ }
+ else {
+ /* NULL terminated string */
+ slen = strlen (p);
+ }
+ }
+
while (slen) {
hexbuf[0] = hex == 2 ? _HEX[(*p >> 4) & 0xf] :
_hex[(*p >> 4) & 0xf];
@@ -609,15 +623,24 @@ rspamd_vprintf_common (rspamd_printf_append_func func,
p++;
slen--;
}
+
fmt++;
buf_start = fmt;
}
else {
+ if (slen == -1) {
+ /* NULL terminated string */
+ slen = strlen (p);
+ }
+
+ if (G_UNLIKELY (width != 0)) {
+ slen = MIN (slen, width);
+ }
+
RSPAMD_PRINTF_APPEND (p, slen);
}
-
continue;
case 'O':