]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
irqtop: use output string in a more robust way
authorKarel Zak <kzak@redhat.com>
Thu, 20 Mar 2025 13:28:17 +0000 (14:28 +0100)
committerKarel Zak <kzak@redhat.com>
Thu, 20 Mar 2025 13:28:17 +0000 (14:28 +0100)
Reporte-by: Benno Schulenberg <bensberg@telfort.nl>
Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/irqtop.c

index c7222f1d3335fafcf0269874db88cb8672fab103..9c9b0ba057f3e08961320ee25a780b554631c074 100644 (file)
@@ -129,7 +129,7 @@ static int update_screen(struct irqtop_ctl *ctl, struct irq_output *out)
        struct libscols_table *table, *cpus = NULL;
        struct irq_stat *stat;
        time_t now = time(NULL);
-       char timestr[64], *data, *data0, *p;
+       char timestr[64], *data, *data0, *p = NULL;
        char *input_file;
 
        /* make irqs table */
@@ -171,7 +171,8 @@ static int update_screen(struct irqtop_ctl *ctl, struct irq_output *out)
        /* print cpus table or not by -c option */
        if (cpus) {
                scols_print_table_to_string(cpus, &data);
-               irqtop_printf(ctl, "%s\n\n", data);
+               if (data && *data)
+                       irqtop_printf(ctl, "%s\n\n", data);
                free(data);
        }
 
@@ -179,7 +180,8 @@ static int update_screen(struct irqtop_ctl *ctl, struct irq_output *out)
        scols_print_table_to_string(table, &data0);
        data = data0;
 
-       p = strchr(data, '\n');
+       if (data && *data)
+               p = strchr(data, '\n');
        if (p) {
                /* print header in reverse mode */
                *p = '\0';
@@ -191,7 +193,8 @@ static int update_screen(struct irqtop_ctl *ctl, struct irq_output *out)
                data = p + 1;
        }
 
-       irqtop_printf(ctl, "%s\n\n", data);
+       if (data && *data)
+               irqtop_printf(ctl, "%s\n\n", data);
        free(data0);
 
        /* clean up */