http: fix memory leak
[vpp.git] / src / vppinfra / format_table.c
index b698cfd..dd92e41 100644 (file)
@@ -52,7 +52,7 @@ format_text_cell (table_t *t, u8 *s, table_cell_t *c, table_text_attr_t *def,
 {
   table_text_attr_t _a = {}, *a = &_a;
 
-  if (a == 0)
+  if (c == 0)
     return format (s, t->no_ansi ? "" : "\x1b[0m");
 
   clib_memcpy (a, def, sizeof (table_text_attr_t));
@@ -64,12 +64,14 @@ format_text_cell (table_t *t, u8 *s, table_cell_t *c, table_text_attr_t *def,
        {
          a->fg_color = c->attr.fg_color;
          a->flags |= TTAF_FG_COLOR_SET;
+         a->flags |= c->attr.flags & TTAF_FG_COLOR_BRIGHT;
        }
 
       if (c->attr.flags & TTAF_BG_COLOR_SET)
        {
          a->bg_color = c->attr.bg_color;
          a->flags |= TTAF_BG_COLOR_SET;
+         a->flags |= c->attr.flags & TTAF_BG_COLOR_BRIGHT;
        }
 
       if (a->flags & TTAF_RESET)
@@ -123,6 +125,7 @@ format_table (u8 *s, va_list *args)
   table_t *t = va_arg (*args, table_t *);
   table_cell_t title_cell = { .text = t->title };
   int table_width = 0;
+  u32 indent = format_get_indent (s);
   for (int i = 0; i < vec_len (t->row_sizes); i++)
     table_width += t->row_sizes[i];
 
@@ -132,7 +135,7 @@ format_table (u8 *s, va_list *args)
       title_default =
        t->default_title.as_u32 ? &t->default_title : &default_title;
       s = format_text_cell (t, s, &title_cell, title_default, table_width);
-      s = format (s, "\n");
+      s = format (s, "\n%U", format_white_space, indent);
     }
 
   for (int c = 0; c < vec_len (t->cells); c++)
@@ -159,7 +162,7 @@ format_table (u8 *s, va_list *args)
                                t->row_sizes[r]);
        }
       if (c + 1 < vec_len (t->cells))
-       s = format (s, "\n");
+       s = format (s, "\n%U", format_white_space, indent);
     }
 
   return s;
@@ -216,16 +219,24 @@ void
 table_set_cell_fg_color (table_t *t, int c, int r, table_text_attr_color_t v)
 {
   table_cell_t *cell = table_get_cell (t, c, r);
-  cell->attr.fg_color = v;
+  cell->attr.fg_color = v & 0x7;
   cell->attr.flags |= TTAF_FG_COLOR_SET;
+  if (v & 8)
+    cell->attr.flags |= TTAF_FG_COLOR_BRIGHT;
+  else
+    cell->attr.flags &= ~TTAF_FG_COLOR_BRIGHT;
 }
 
 void
 table_set_cell_bg_color (table_t *t, int c, int r, table_text_attr_color_t v)
 {
   table_cell_t *cell = table_get_cell (t, c, r);
-  cell->attr.bg_color = v;
+  cell->attr.bg_color = v & 0x7;
   cell->attr.flags |= TTAF_BG_COLOR_SET;
+  if (v & 8)
+    cell->attr.flags |= TTAF_BG_COLOR_BRIGHT;
+  else
+    cell->attr.flags &= ~TTAF_BG_COLOR_BRIGHT;
 }
 
 void