From: Michael Tremer Date: Tue, 1 Jul 2025 16:30:35 +0000 (+0000) Subject: cli: table: Check that we have the correct number of columns X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=893709088022834e372503559e170ffdfd4344e7;p=pakfire.git cli: table: Check that we have the correct number of columns Signed-off-by: Michael Tremer --- diff --git a/src/cli/lib/table.c b/src/cli/lib/table.c index 366f13c0..0521dff6 100644 --- a/src/cli/lib/table.c +++ b/src/cli/lib/table.c @@ -187,6 +187,7 @@ int cli_table_add_col(cli_table* self, const char* name, cli_table_col_type type int cli_table_add_row(cli_table* self, ...) { cli_table_col* col = NULL; cli_table_row* row = NULL; + unsigned int cols = 0; char buffer[1024]; size_t width = 0; va_list args; @@ -237,10 +238,19 @@ int cli_table_add_row(cli_table* self, ...) { // Adjust the required width of the column if (width > col->width) col->width = width; + + // Count the cols + cols++; } va_end(args); + // Fail if we had an incorrect number of columns + if (cols != self->num_cols) { + r = -EINVAL; + goto ERROR; + } + // Append the row STAILQ_INSERT_TAIL(&self->rows, row, nodes);