Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

colprint: Fix column width truncation #3725

Merged
merged 1 commit into from
May 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions main/colprint.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ enum colprintJustification {
struct colprintHeaderColumn {
vString *value;
enum colprintJustification justification;
unsigned int maxWidth;
size_t maxWidth;
bool needPrefix;
};

Expand All @@ -36,7 +36,7 @@ struct colprintTable {
ptrArray *lines;
};

static void fillWithWhitespaces (int i, FILE *fp)
static void fillWithWhitespaces (size_t i, FILE *fp)
{
while (i-- > 0)
{
Expand Down Expand Up @@ -119,7 +119,7 @@ void colprintTableDelete (struct colprintTable *table)

static void colprintColumnPrintGeneric (vString *column, struct colprintHeaderColumn *spec, bool machinable, FILE *fp)
{
int maxWidth = spec->maxWidth + (spec->needPrefix? 1: 0);
size_t maxWidth = spec->maxWidth + (spec->needPrefix? 1: 0);

if ((column == spec->value) && (spec->needPrefix))
{
Expand All @@ -135,7 +135,10 @@ static void colprintColumnPrintGeneric (vString *column, struct colprintHeaderCo
}
else
{
int padLen = maxWidth - vStringLength (column);
size_t padLen = 0;
size_t colLen = vStringLength (column);
if (colLen < maxWidth)
padLen = maxWidth - colLen;
if (spec->justification == COLPRINT_LEFT
|| spec->justification == COLPRINT_LAST)
{
Expand Down