Skip to content

Commit cf258a9

Browse files
committed
Merge branch 'kh/column-reject-negative-padding'
"git column" has been taught to reject negative padding value, as it would lead to nonsense behaviour including division by zero. * kh/column-reject-negative-padding: column: guard against negative padding column: disallow negative padding
2 parents 225f892 + 76fb807 commit cf258a9

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

builtin/column.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ int cmd_column(int argc, const char **argv, const char *prefix)
4545
memset(&copts, 0, sizeof(copts));
4646
copts.padding = 1;
4747
argc = parse_options(argc, argv, prefix, options, builtin_column_usage, 0);
48+
if (copts.padding < 0)
49+
die(_("%s must be non-negative"), "--padding");
4850
if (argc)
4951
usage_with_options(builtin_column_usage, options);
5052
if (real_command || command) {

column.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ void print_columns(const struct string_list *list, unsigned int colopts,
182182
{
183183
struct column_options nopts;
184184

185+
if (opts && (0 > opts->padding))
186+
BUG("padding must be non-negative");
185187
if (!list->nr)
186188
return;
187189
assert((colopts & COL_ENABLE_MASK) != COL_AUTO);
@@ -361,6 +363,8 @@ int run_column_filter(int colopts, const struct column_options *opts)
361363
{
362364
struct strvec *argv;
363365

366+
if (opts && (0 > opts->padding))
367+
BUG("padding must be non-negative");
364368
if (fd_out != -1)
365369
return -1;
366370

t/t9002-column.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,4 +196,15 @@ EOF
196196
test_cmp expected actual
197197
'
198198

199+
test_expect_success 'padding must be non-negative' '
200+
cat >input <<\EOF &&
201+
1 2 3 4 5 6
202+
EOF
203+
cat >expected <<\EOF &&
204+
fatal: --padding must be non-negative
205+
EOF
206+
test_must_fail git column --mode=column --padding=-1 <input >actual 2>&1 &&
207+
test_cmp expected actual
208+
'
209+
199210
test_done

0 commit comments

Comments
 (0)