]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
doveadm-log: Fixed trimming empty prefixes.
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 26 Feb 2016 13:25:27 +0000 (15:25 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 26 Feb 2016 13:27:36 +0000 (15:27 +0200)
Too eager (long) cast removal from the original code broke it. Changed to
a slightly simplified version now.

src/doveadm/doveadm-log.c

index 97c17c6cec15569a783c1d43a23a4d97c450279b..e50898a905cafe3b894f891798802713ab997551 100644 (file)
@@ -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)