33 *
44 * Copyright (c) 2000-2005, PostgreSQL Global Development Group
55 *
6- * $PostgreSQL: pgsql/src/bin/psql/print.c,v 1.61 2005/07/1003:46:13 momjian Exp $
6+ * $PostgreSQL: pgsql/src/bin/psql/print.c,v 1.62 2005/07/1015:48:14 momjian Exp $
77 */
88#include "postgres_fe.h"
99#include "common.h"
@@ -77,12 +77,7 @@ format_numericsep(char *my_str, char *numericsep)
7777if (digits_before_sep == 0 )
7878new_len -- ;/* no leading separator */
7979
80- new_str = malloc (new_len );
81- if (!new_str )
82- {
83- fprintf (stderr ,_ ("out of memory\n" ));
84- exit (EXIT_FAILURE );
85- }
80+ new_str = pg_malloc (new_len );
8681
8782for (i = 0 ,j = 0 ; ;i ++ ,j ++ )
8883{
@@ -167,13 +162,8 @@ print_unaligned_text(const char *title, const char *const *headers,
167162if ((opt_align [i %col_count ]== 'r' )&& strlen (* ptr )> 0 &&
168163opt_numericsep != NULL && strlen (opt_numericsep )> 0 )
169164{
170- char * my_cell = malloc (len_with_numericsep (* ptr ));
165+ char * my_cell = pg_malloc (len_with_numericsep (* ptr ));
171166
172- if (!my_cell )
173- {
174- fprintf (stderr ,_ ("out of memory\n" ));
175- exit (EXIT_FAILURE );
176- }
177167strcpy (my_cell ,* ptr );
178168format_numericsep (my_cell ,opt_numericsep );
179169fputs (my_cell ,fout );
@@ -249,13 +239,8 @@ print_unaligned_vertical(const char *title, const char *const *headers,
249239if ((opt_align [i %col_count ]== 'r' )&& strlen (* ptr )!= 0 &&
250240opt_numericsep != NULL && strlen (opt_numericsep )> 0 )
251241{
252- char * my_cell = malloc (len_with_numericsep (* ptr ));
242+ char * my_cell = pg_malloc (len_with_numericsep (* ptr ));
253243
254- if (!my_cell )
255- {
256- fprintf (stderr ,_ ("out of memory\n" ));
257- exit (EXIT_FAILURE );
258- }
259244strcpy (my_cell ,* ptr );
260245format_numericsep (my_cell ,opt_numericsep );
261246fputs (my_cell ,fout );
@@ -482,13 +467,8 @@ print_aligned_text(const char *title, const char *const *headers,
482467{
483468if (strlen (* ptr )> 0 && opt_numericsep != NULL && strlen (opt_numericsep )> 0 )
484469 {
485- char * my_cell = malloc (cell_w [i ]);
470+ char * my_cell = pg_malloc (cell_w [i ]);
486471
487- if (!my_cell )
488- {
489- fprintf (stderr ,_ ("out of memory\n" ));
490- exit (EXIT_FAILURE );
491- }
492472strcpy (my_cell ,* ptr );
493473format_numericsep (my_cell ,opt_numericsep );
494474fprintf (fout ,"%*s%s" ,widths [i %col_count ]- cell_w [i ],"" ,my_cell );
@@ -634,12 +614,7 @@ print_aligned_vertical(const char *title, const char *const *headers,
634614fprintf (fout ,"%s\n" ,title );
635615
636616/* make horizontal border */
637- divider = malloc (hwidth + dwidth + 10 );
638- if (!divider )
639- {
640- fprintf (stderr ,_ ("out of memory\n" ));
641- exit (EXIT_FAILURE );
642- }
617+ divider = pg_malloc (hwidth + dwidth + 10 );
643618divider [0 ]= '\0' ;
644619if (opt_border == 2 )
645620strcat (divider ,"+-" );
@@ -661,15 +636,9 @@ print_aligned_vertical(const char *title, const char *const *headers,
661636{
662637if (!opt_barebones )
663638{
664- char * record_str = malloc (32 );
639+ char * record_str = pg_malloc (32 );
665640size_t record_str_len ;
666641
667- if (!record_str )
668- {
669- fprintf (stderr ,_ ("out of memory\n" ));
670- exit (EXIT_FAILURE );
671- }
672-
673642if (opt_border == 0 )
674643snprintf (record_str ,32 ,"* Record %d" ,record ++ );
675644else
@@ -709,13 +678,8 @@ print_aligned_vertical(const char *title, const char *const *headers,
709678fputs (" " ,fout );
710679
711680{
712- char * my_cell = malloc (cell_w [i ]);
681+ char * my_cell = pg_malloc (cell_w [i ]);
713682
714- if (!my_cell )
715- {
716- fprintf (stderr ,_ ("out of memory\n" ));
717- exit (EXIT_FAILURE );
718- }
719683strcpy (my_cell ,* ptr );
720684if ((opt_align [i %col_count ]== 'r' )&& strlen (* ptr )!= 0 &&
721685opt_numericsep != NULL && strlen (opt_numericsep )> 0 )
@@ -855,13 +819,8 @@ print_html_text(const char *title, const char *const *headers,
855819else if ((opt_align [i %col_count ]== 'r' )&& strlen (* ptr )!= 0 &&
856820opt_numericsep != NULL && strlen (opt_numericsep )> 0 )
857821{
858- char * my_cell = malloc (len_with_numericsep (* ptr ));
822+ char * my_cell = pg_malloc (len_with_numericsep (* ptr ));
859823
860- if (!my_cell )
861- {
862- fprintf (stderr ,_ ("out of memory\n" ));
863- exit (EXIT_FAILURE );
864- }
865824strcpy (my_cell ,* ptr );
866825format_numericsep (my_cell ,opt_numericsep );
867826html_escaped_print (my_cell ,fout );
@@ -946,13 +905,8 @@ print_html_vertical(const char *title, const char *const *headers,
946905else if ((opt_align [i %col_count ]== 'r' )&& strlen (* ptr )!= 0 &&
947906opt_numericsep != NULL && strlen (opt_numericsep )> 0 )
948907{
949- char * my_cell = malloc (len_with_numericsep (* ptr ));
908+ char * my_cell = pg_malloc (len_with_numericsep (* ptr ));
950909
951- if (!my_cell )
952- {
953- fprintf (stderr ,_ ("out of memory\n" ));
954- exit (EXIT_FAILURE );
955- }
956910strcpy (my_cell ,* ptr );
957911format_numericsep (my_cell ,opt_numericsep );
958912html_escaped_print (my_cell ,fout );
@@ -1646,12 +1600,7 @@ printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, FILE *f
16461600exit (EXIT_FAILURE );
16471601}
16481602
1649- footers [0 ]= malloc (100 );
1650- if (!footers [0 ])
1651- {
1652- fprintf (stderr ,_ ("out of memory\n" ));
1653- exit (EXIT_FAILURE );
1654- }
1603+ footers [0 ]= pg_malloc (100 );
16551604if (PQntuples (result )== 1 )
16561605snprintf (footers [0 ],100 ,_ ("(1 row)" ));
16571606else