Readability enchancement, and few variable type changes to be more proper. Signed-off-by: Sami Kerola <kerolasa@xxxxxx> --- text-utils/column.c | 32 +++++++++++++++++++------------- 1 files changed, 19 insertions(+), 13 deletions(-) diff --git a/text-utils/column.c b/text-utils/column.c index 77dabd2..9605afb 100644 --- a/text-utils/column.c +++ b/text-utils/column.c @@ -267,9 +267,10 @@ static void print() static void maketbl() { TBL *t; - int coloff, cnt, i; + int cnt, i; wchar_t *p, **lp; - int *lens, maxcols = DEFCOLS; + int *lens; + ssize_t maxcols = DEFCOLS, coloff; TBL *tbl; wchar_t **cols; wchar_t *wcstok_state; @@ -277,19 +278,21 @@ static void maketbl() t = tbl = xcalloc(entries, sizeof(TBL)); cols = xcalloc(maxcols, sizeof(wchar_t *)); lens = xcalloc(maxcols, sizeof(int)); - for (cnt = 0, lp = list; cnt < entries; ++cnt, ++lp, ++t) { - for (coloff = 0, p = *lp; - (cols[coloff] = wcstok(p, separator, &wcstok_state)) != NULL; - p = NULL) { + lp = list; + + for (cnt = 0; cnt < entries; ++cnt, ++lp, ++t) { + coloff = 0; + p = *lp; + while ((cols[coloff] = wcstok(p, separator, &wcstok_state)) != NULL) { if (++coloff == maxcols) { - cols = xrealloc(cols, ((u_int)maxcols + DEFCOLS) - * sizeof(wchar_t *)); - lens = xrealloc(lens, ((u_int)maxcols + DEFCOLS) - * sizeof(int)); - memset((char *)lens + maxcols * sizeof(int), - 0, DEFCOLS * sizeof(int)); maxcols += DEFCOLS; + cols = xrealloc(cols, maxcols * sizeof(wchar_t *)); + lens = xrealloc(lens, maxcols * sizeof(int)); + /* zero fill only new memory */ + memset(lens + (maxcols - DEFCOLS), 0, + DEFCOLS * sizeof(int)); } + p = NULL; } t->list = xcalloc(coloff, sizeof(wchar_t *)); t->len = xcalloc(coloff, sizeof(int)); @@ -300,7 +303,10 @@ static void maketbl() lens[coloff] = t->len[coloff]; } } - for (cnt = 0, t = tbl; cnt < entries; ++cnt, ++t) { + + t = tbl; + + for (cnt = 0; cnt < entries; ++cnt, ++t) { for (coloff = 0; coloff < t->cols - 1; ++coloff) { fputws(t->list[coloff], stdout); for (i = lens[coloff] - t->len[coloff] + 2; i > 0; i--) -- 1.7.5 -- To unsubscribe from this list: send the line "unsubscribe util-linux" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html