ensure at least two spaces of cell-to-cell horizontal padding in print_columns;

audit all callers of print_columns to always pass the exact maximum sizes
This commit is contained in:
tg 2015-07-05 14:58:33 +00:00
parent 69eac312de
commit 5eeeaab8cf

15
misc.c
View File

@ -30,7 +30,7 @@
#include <grp.h> #include <grp.h>
#endif #endif
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.235 2015/07/05 14:47:41 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/misc.c,v 1.236 2015/07/05 14:58:33 tg Exp $");
#define KSH_CHVT_FLAG #define KSH_CHVT_FLAG
#ifdef MKSH_SMALL #ifdef MKSH_SMALL
@ -1255,11 +1255,12 @@ print_columns(struct shf *shf, unsigned int n,
str = alloc(max_oct, ATEMP); str = alloc(max_oct, ATEMP);
/* /*
* We use (max_col + 1) to consider the space separator. * We use (max_col + 2) to consider the separator space.
* Note that no space is printed after the last column * Note that no spaces are printed after the last column
* to avoid problems with terminals that have auto-wrap. * to avoid problems with terminals that have auto-wrap,
* but we need to also take this into account in x_cols.
*/ */
cols = x_cols / (max_col + 1); cols = (x_cols + 1) / (max_col + 2);
/* if we can only print one column anyway, skip the goo */ /* if we can only print one column anyway, skip the goo */
if (cols < 2) { if (cols < 2) {
@ -1278,9 +1279,9 @@ print_columns(struct shf *shf, unsigned int n,
} }
nspace = (x_cols - max_col * cols) / cols; nspace = (x_cols - max_col * cols) / cols;
if (nspace < 2)
nspace = 2;
max_col = -max_col; max_col = -max_col;
if (nspace <= 0)
nspace = 1;
for (r = 0; r < rows; r++) { for (r = 0; r < rows; r++) {
for (c = 0; c < cols; c++) { for (c = 0; c < cols; c++) {
if ((i = c * rows + r) >= n) if ((i = c * rows + r) >= n)