chiark / gitweb /
journalctl: fix assertion failure in ellipsize_mem()
authorEelco Dolstra <eelco.dolstra@logicblox.com>
Thu, 19 Jul 2012 21:12:16 +0000 (21:12 +0000)
committerLennart Poettering <lennart@poettering.net>
Thu, 19 Jul 2012 22:12:30 +0000 (00:12 +0200)
When showing the journal through "journalctl --no-pager", if the
prefix of the log message (i.e. the date and syslog identifier) is
less than 3 characters shorter than the width of the terminal, you
get:

Assertion 'new_length >= 3' failed at src/shared/util.c:3859, function ellipsize_mem(). Aborting.

because there is not enough space for the "...".  This patch add the
necessary check.

src/shared/logs-show.c

index 43e42f78803cda5ca7d613514286636f5a698508..a68cd3de57bff6f175bbba920c273185501596d5 100644 (file)
@@ -228,7 +228,7 @@ static int output_short(sd_journal *j, unsigned line, unsigned n_columns,
         } else if ((flags & OUTPUT_FULL_WIDTH) ||
                    (message_len + n < n_columns))
                 printf(": %.*s\n", (int) message_len, message);
         } else if ((flags & OUTPUT_FULL_WIDTH) ||
                    (message_len + n < n_columns))
                 printf(": %.*s\n", (int) message_len, message);
-        else if (n < n_columns) {
+        else if (n < n_columns && n_columns - n - 2 >= 3) {
                 char *e;
 
                 e = ellipsize_mem(message, message_len, n_columns - n - 2, 90);
                 char *e;
 
                 e = ellipsize_mem(message, message_len, n_columns - n - 2, 90);