Skip to content

Commit

Permalink
colprint: Fix column width truncation
Browse files Browse the repository at this point in the history
This is very theoretical though, but pleases -Wconversion.
  • Loading branch information
b4n committed May 15, 2023
1 parent ee10ac3 commit 3547021
Showing 1 changed file with 7 additions and 4 deletions.
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

0 comments on commit 3547021

Please sign in to comment.