From: Kristoffer Haugsbakk Date: Mon, 12 Feb 2024 16:50:54 GMT Subject: Re: [PATCH v2] column: disallow negative padding Message-ID: <09b1ab48-b58f-458c-89f5-0c419d92f61a@app.fastmail.com> In-Reply-To: <89d32a5f-b5ab-4773-bd9f-d33b4e348e15@gmail.com> On Sun, Feb 11, 2024, at 23:47, Rubén Justo wrote: > While we're here, I wonder if silently ignoring a negative value in > .padding is the right thing to do. > > There are several callers of print_columns(): > > builtin/branch.c: print_columns(&output, colopts, NULL); > builtin/clean.c: print_columns(&list, colopts, &copts); > builtin/clean.c: print_columns(menu_list, local_colopts, &copts); > builtin/column.c: print_columns(&list, colopts, &copts); > help.c: print_columns(&list, colopts, &copts); > wt-status.c: print_columns(&output, s->colopts, &copts); > > I haven't checked it thoroughly but it seems we don't need to add the > check we're adding to builtin/column.c, to any of the other callers. > However, it is possible that these or other new callers may need it in > the future. If so, we should consider doing something like: > > diff --git a/column.c b/column.c > index c723428bc7..4f870c725f 100644 > --- a/column.c > +++ b/column.c > @@ -186,6 +186,9 @@ void print_columns(const struct string_list *list, > unsigned int colopts, > return; > assert((colopts & COL_ENABLE_MASK) != COL_AUTO); > > + if (opts && (0 <= opts->padding)) > + BUG("padding must be non-negative"); > + Sure, I could add a `BUG` for `0 > opts->padding` in v3.