Skip site navigation (1) Skip section navigation (2)

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search for
  Advanced Search

Re: \x output blowing up


  • From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
  • To: Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us>
  • Cc: pgsql-hackers(at)postgresql(dot)org
  • Subject: Re: \x output blowing up
  • Date: Sun, 25 Sep 2005 11:18:36 +0200
  • Message-id: <20050925091829(dot)GA7743(at)svana(dot)org>

On Sat, Sep 24, 2005 at 07:18:16PM -0400, Bruce Momjian wrote:
> 
> Well, it seems we are going to have to fix it somehow for 8.1.  It is
> not crashing here so I can't work up a patch.  Can you submit a minimal
> fix for 8.1?  Thanks.

Ah, it would only happen if your encoding was UTF-8 since that's the
only case psql handles differently. I've attached a patch which fixes
it. With a bit more rearrangement you could probably simplify it a bit
but this works.

Have a nice day,
-- 
Martijn van Oosterhout   <kleptog(at)svana(dot)org>   http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.
Index: print.c
===================================================================
RCS file: /projects/cvsroot/pgsql/src/bin/psql/print.c,v
retrieving revision 1.74
diff -c -r1.74 print.c
*** print.c	24 Sep 2005 17:53:27 -0000	1.74
--- print.c	25 Sep 2005 09:16:01 -0000
***************
*** 697,714 ****
  		else
  			fputs(" ", fout);
  
  		{
  			char *my_cell = pg_local_malloc(cell_w[i] + 1);
  
  			strcpy(my_cell, *ptr);
! 			if (opt_align[i % col_count] == 'r' && opt_numeric_locale)
! 			    format_numeric_locale(my_cell);
  			if (opt_border < 2)
  				fprintf(fout, "%s\n", my_cell);
  			else
  				fprintf(fout, "%-s%*s |\n", my_cell, dwidth - cell_w[i], "");
  			free(my_cell);
  		}
  	}
  
  	if (opt_border == 2)
--- 697,726 ----
  		else
  			fputs(" ", fout);
  
+ 		/* We seperate the cases for numeric_locale because for UTF-8 (and
+ 		 * other) encodings, cell_w <= strlen(*ptr). We can't just use
+ 		 * strlen() in the malloc because there needs to be enough room for
+ 		 * format_numeric_locale() to store its result. */
+ 
+ 		if (opt_align[i % col_count] == 'r' && opt_numeric_locale)
  		{
  			char *my_cell = pg_local_malloc(cell_w[i] + 1);
  
  			strcpy(my_cell, *ptr);
! 			format_numeric_locale(my_cell);
  			if (opt_border < 2)
  				fprintf(fout, "%s\n", my_cell);
  			else
  				fprintf(fout, "%-s%*s |\n", my_cell, dwidth - cell_w[i], "");
  			free(my_cell);
  		}
+ 		else
+ 		{
+ 			if (opt_border < 2)
+ 				fprintf(fout, "%s\n", *ptr);
+ 			else
+ 				fprintf(fout, "%-s%*s |\n", *ptr, dwidth - cell_w[i], "");
+ 		}
  	}
  
  	if (opt_border == 2)

Attachment: pgp0wyYaipmyQ.pgp
Description: PGP signature



Home | Main Index | Thread Index

Privacy Policy | PostgreSQL Archives hosted by Command Prompt, Inc. | Designed by tinysofa
Copyright © 1996 – 2008 PostgreSQL Global Development Group