Skip to content

Commit

Permalink
doveadm-log: Fixed trimming empty prefixes.
Browse files Browse the repository at this point in the history
Too eager (long) cast removal from the original code broke it. Changed to
a slightly simplified version now.
  • Loading branch information
sirainen committed Feb 26, 2016
1 parent 50e4970 commit 96f35f2
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/doveadm/doveadm-log.c
Expand Up @@ -281,19 +281,17 @@ static void cmd_log_find(int argc, char *argv[])

static const char *t_cmd_log_error_trim(const char *orig)
{
/* use long in case strlen returns 0 */
for (unsigned int pos = strlen(orig)-1; pos > 0; pos--) {
if (orig[pos] != ' ') {
if (orig[pos] != ':') {
pos++;
}
if (pos < strlen(orig)-1) {
return t_strndup(orig, pos);
}
unsigned int pos;

/* Trim whitespace from suffix and remove ':' if it exists */
for (pos = strlen(orig); pos > 0; pos--) {
if (orig[pos-1] != ' ') {
if (orig[pos-1] == ':')
pos--;
break;
}
}
return orig;
return orig[pos] == '\0' ? orig : t_strndup(orig, pos);
}

static void cmd_log_error_write(const char *const *args, time_t min_timestamp)
Expand Down

0 comments on commit 96f35f2

Please sign in to comment.