]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
format-table: simplify table_set_display_all() and keep it private
authorLennart Poettering <lennart@poettering.net>
Thu, 4 Mar 2021 19:50:34 +0000 (20:50 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Mon, 8 Mar 2021 21:33:35 +0000 (21:33 +0000)
src/shared/format-table.c
src/shared/format-table.h

index ae56cd3d6788fea799e97ef95cf1b42751aab922..6bbc8bd509e1dfc9b0562b5b3336bcfbaa331e3b 100644 (file)
@@ -1078,17 +1078,21 @@ int table_set_empty_string(Table *t, const char *empty) {
         return free_and_strdup(&t->empty_string, empty);
 }
 
-int table_set_display_all(Table *t) {
+static int table_set_display_all(Table *t) {
+        size_t *d;
+
         assert(t);
 
-        size_t allocated = t->n_display_map;
+        /* Initialize the display map to the identity */
 
-        if (!GREEDY_REALLOC(t->display_map, allocated, MAX(t->n_columns, allocated)))
+        d = reallocarray(t->display_map, t->n_columns, sizeof(size_t));
+        if (!d)
                 return -ENOMEM;
 
         for (size_t i = 0; i < t->n_columns; i++)
-                t->display_map[i] = i;
+                d[i] = i;
 
+        t->display_map = d;
         t->n_display_map = t->n_columns;
 
         return 0;
index d1935456f0aeabe29f9bd51c0e83483c1038677b..57f167f7f11eb749db15863d61b61dea79015e2a 100644 (file)
@@ -100,7 +100,6 @@ void table_set_header(Table *table, bool b);
 void table_set_width(Table *t, size_t width);
 void table_set_cell_height_max(Table *t, size_t height);
 int table_set_empty_string(Table *t, const char *empty);
-int table_set_display_all(Table *t);
 int table_set_display_internal(Table *t, size_t first_column, ...);
 #define table_set_display(...) table_set_display_internal(__VA_ARGS__, SIZE_MAX)
 int table_set_sort_internal(Table *t, size_t first_column, ...);