Skip to content

Commit 2e27b0e

Browse files
committed
Fix utterly-bogus code for computing row heights. Per crashes on
spoonbill, though one wonders why it didn't misbehave everywhere. In passing remove some unnecessary modulo calculations.
1 parent 1a604b4 commit 2e27b0e

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

src/bin/psql/print.c

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2008, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/print.c,v 1.103 2008/05/16 18:35:38 tgl Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/print.c,v 1.104 2008/05/17 17:52:14 tgl Exp $
77
*/
88
#include "postgres_fe.h"
99

@@ -522,7 +522,7 @@ print_aligned_text(const printTableContent *cont, FILE *fout)
522522
int rows = cell_count / col_count;
523523

524524
for (i = 0; i < col_count; i++)
525-
width_average[i % col_count] /= rows;
525+
width_average[i] /= rows;
526526
}
527527

528528
/* adjust the total display width based on border style */
@@ -645,30 +645,36 @@ print_aligned_text(const printTableContent *cont, FILE *fout)
645645
if (!is_pager)
646646
{
647647
/* scan all cells, find maximum width, compute cell_count */
648-
for (i = 0, ptr = cont->cells; *ptr; ptr++, i++, cell_count++)
648+
for (i = 0, ptr = cont->cells; *ptr; ptr++, cell_count++)
649649
{
650650
int width,
651651
nl_lines,
652652
bytes_required;
653653

654654
pg_wcssize((unsigned char *) *ptr, strlen(*ptr), encoding,
655655
&width, &nl_lines, &bytes_required);
656-
if (opt_numeric_locale && cont->align[i % col_count] == 'r')
656+
if (opt_numeric_locale && cont->align[i] == 'r')
657657
width += additional_numeric_locale_len(*ptr);
658658

659659
/*
660660
* A row can have both wrapping and newlines that cause
661661
* it to display across multiple lines. We check
662662
* for both cases below.
663663
*/
664-
if (width > 0 && width_wrap[i] &&
665-
(width-1) / width_wrap[i] + nl_lines > extra_row_output_lines)
666-
extra_row_output_lines = (width-1) / width_wrap[i] + nl_lines;
664+
if (width > 0 && width_wrap[i])
665+
{
666+
unsigned int extra_lines;
667+
668+
extra_lines = (width-1) / width_wrap[i] + nl_lines;
669+
if (extra_lines > extra_row_output_lines)
670+
extra_row_output_lines = extra_lines;
671+
}
667672

668-
/* If last column, add tallest column height */
669-
if (i % col_count == col_count - 1)
673+
/* i is the current column number: increment with wrap */
674+
if (++i >= col_count)
670675
{
671-
/* Add height of tallest row */
676+
i = 0;
677+
/* At last column of each row, add tallest column height */
672678
extra_output_lines += extra_row_output_lines;
673679
extra_row_output_lines = 0;
674680
}
@@ -780,7 +786,7 @@ print_aligned_text(const printTableContent *cont, FILE *fout)
780786
col_lineptrs[j], max_nl_lines[j]);
781787
curr_nl_line[j] = 0;
782788

783-
if (opt_numeric_locale && cont->aligns[j % col_count] == 'r')
789+
if (opt_numeric_locale && cont->aligns[j] == 'r')
784790
{
785791
char *my_cell;
786792

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy