Browse Source

[Minor] Tune printf for hex and base32 input strings

tags/1.4.0
Vsevolod Stakhov 7 years ago
parent
commit
afb5308643
1 changed files with 33 additions and 10 deletions
  1. 33
    10
      src/libutil/printf.c

+ 33
- 10
src/libutil/printf.c View File

p = "(NULL)"; p = "(NULL)";
} }


if (slen == -1) {
/* NULL terminated string */
slen = strlen (p);
}

if (G_UNLIKELY (width != 0)) {
slen = MIN (slen, width);
}

if (G_UNLIKELY (b32)) { if (G_UNLIKELY (b32)) {
gchar *b32buf; 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); b32buf = rspamd_encode_base32 (p, slen);


if (b32buf) { if (b32buf) {
RSPAMD_PRINTF_APPEND (b32buf, strlen (b32buf)); RSPAMD_PRINTF_APPEND (b32buf, strlen (b32buf));
g_free (b32buf); g_free (b32buf);
} }
else {
RSPAMD_PRINTF_APPEND ("(NULL)", sizeof ("(NULL)") - 1);
}
} }
else if (G_UNLIKELY (hex)) { else if (G_UNLIKELY (hex)) {
gchar hexbuf[2]; gchar hexbuf[2];


if (G_UNLIKELY (slen == -1)) {
if (G_LIKELY (width != 0)) {
slen = width;
}
else {
/* NULL terminated string */
slen = strlen (p);
}
}

while (slen) { while (slen) {
hexbuf[0] = hex == 2 ? _HEX[(*p >> 4) & 0xf] : hexbuf[0] = hex == 2 ? _HEX[(*p >> 4) & 0xf] :
_hex[(*p >> 4) & 0xf]; _hex[(*p >> 4) & 0xf];
p++; p++;
slen--; slen--;
} }

fmt++; fmt++;
buf_start = fmt; buf_start = fmt;


} }
else { else {
if (slen == -1) {
/* NULL terminated string */
slen = strlen (p);
}

if (G_UNLIKELY (width != 0)) {
slen = MIN (slen, width);
}

RSPAMD_PRINTF_APPEND (p, slen); RSPAMD_PRINTF_APPEND (p, slen);
} }



continue; continue;


case 'O': case 'O':

Loading…
Cancel
Save