33 *
44 * Copyright (c) 2000-2005, PostgreSQL Global Development Group
55 *
6- * $PostgreSQL: pgsql/src/bin/psql/print.c,v 1.62 2005/07/10 15:48:14 momjian Exp $
6+ * $PostgreSQL: pgsql/src/bin/psql/print.c,v 1.63 2005/07/10 15:53:42 momjian Exp $
77 */
88#include "postgres_fe.h"
99#include "common.h"
@@ -77,7 +77,12 @@ format_numericsep(char *my_str, char *numericsep)
7777if (digits_before_sep == 0 )
7878new_len -- ;/* no leading separator */
7979
80- new_str = pg_malloc (new_len );
80+ new_str = malloc (new_len );
81+ if (!new_str )
82+ {
83+ fprintf (stderr ,_ ("out of memory\n" ));
84+ exit (EXIT_FAILURE );
85+ }
8186
8287for (i = 0 ,j = 0 ; ;i ++ ,j ++ )
8388{
@@ -162,8 +167,13 @@ print_unaligned_text(const char *title, const char *const *headers,
162167if ((opt_align [i %col_count ]== 'r' )&& strlen (* ptr )> 0 &&
163168opt_numericsep != NULL && strlen (opt_numericsep )> 0 )
164169{
165- char * my_cell = pg_malloc (len_with_numericsep (* ptr ));
170+ char * my_cell = malloc (len_with_numericsep (* ptr ));
166171
172+ if (!my_cell )
173+ {
174+ fprintf (stderr ,_ ("out of memory\n" ));
175+ exit (EXIT_FAILURE );
176+ }
167177strcpy (my_cell ,* ptr );
168178format_numericsep (my_cell ,opt_numericsep );
169179fputs (my_cell ,fout );
@@ -239,8 +249,13 @@ print_unaligned_vertical(const char *title, const char *const *headers,
239249if ((opt_align [i %col_count ]== 'r' )&& strlen (* ptr )!= 0 &&
240250opt_numericsep != NULL && strlen (opt_numericsep )> 0 )
241251{
242- char * my_cell = pg_malloc (len_with_numericsep (* ptr ));
252+ char * my_cell = malloc (len_with_numericsep (* ptr ));
243253
254+ if (!my_cell )
255+ {
256+ fprintf (stderr ,_ ("out of memory\n" ));
257+ exit (EXIT_FAILURE );
258+ }
244259strcpy (my_cell ,* ptr );
245260format_numericsep (my_cell ,opt_numericsep );
246261fputs (my_cell ,fout );
@@ -467,8 +482,13 @@ print_aligned_text(const char *title, const char *const *headers,
467482{
468483if (strlen (* ptr )> 0 && opt_numericsep != NULL && strlen (opt_numericsep )> 0 )
469484 {
470- char * my_cell = pg_malloc (cell_w [i ]);
485+ char * my_cell = malloc (cell_w [i ]);
471486
487+ if (!my_cell )
488+ {
489+ fprintf (stderr ,_ ("out of memory\n" ));
490+ exit (EXIT_FAILURE );
491+ }
472492strcpy (my_cell ,* ptr );
473493format_numericsep (my_cell ,opt_numericsep );
474494fprintf (fout ,"%*s%s" ,widths [i %col_count ]- cell_w [i ],"" ,my_cell );
@@ -614,7 +634,12 @@ print_aligned_vertical(const char *title, const char *const *headers,
614634fprintf (fout ,"%s\n" ,title );
615635
616636/* make horizontal border */
617- divider = pg_malloc (hwidth + dwidth + 10 );
637+ divider = malloc (hwidth + dwidth + 10 );
638+ if (!divider )
639+ {
640+ fprintf (stderr ,_ ("out of memory\n" ));
641+ exit (EXIT_FAILURE );
642+ }
618643divider [0 ]= '\0' ;
619644if (opt_border == 2 )
620645strcat (divider ,"+-" );
@@ -636,9 +661,15 @@ print_aligned_vertical(const char *title, const char *const *headers,
636661{
637662if (!opt_barebones )
638663{
639- char * record_str = pg_malloc (32 );
664+ char * record_str = malloc (32 );
640665size_t record_str_len ;
641666
667+ if (!record_str )
668+ {
669+ fprintf (stderr ,_ ("out of memory\n" ));
670+ exit (EXIT_FAILURE );
671+ }
672+
642673if (opt_border == 0 )
643674snprintf (record_str ,32 ,"* Record %d" ,record ++ );
644675else
@@ -678,8 +709,13 @@ print_aligned_vertical(const char *title, const char *const *headers,
678709fputs (" " ,fout );
679710
680711{
681- char * my_cell = pg_malloc (cell_w [i ]);
712+ char * my_cell = malloc (cell_w [i ]);
682713
714+ if (!my_cell )
715+ {
716+ fprintf (stderr ,_ ("out of memory\n" ));
717+ exit (EXIT_FAILURE );
718+ }
683719strcpy (my_cell ,* ptr );
684720if ((opt_align [i %col_count ]== 'r' )&& strlen (* ptr )!= 0 &&
685721opt_numericsep != NULL && strlen (opt_numericsep )> 0 )
@@ -819,8 +855,13 @@ print_html_text(const char *title, const char *const *headers,
819855else if ((opt_align [i %col_count ]== 'r' )&& strlen (* ptr )!= 0 &&
820856opt_numericsep != NULL && strlen (opt_numericsep )> 0 )
821857{
822- char * my_cell = pg_malloc (len_with_numericsep (* ptr ));
858+ char * my_cell = malloc (len_with_numericsep (* ptr ));
823859
860+ if (!my_cell )
861+ {
862+ fprintf (stderr ,_ ("out of memory\n" ));
863+ exit (EXIT_FAILURE );
864+ }
824865strcpy (my_cell ,* ptr );
825866format_numericsep (my_cell ,opt_numericsep );
826867html_escaped_print (my_cell ,fout );
@@ -905,8 +946,13 @@ print_html_vertical(const char *title, const char *const *headers,
905946else if ((opt_align [i %col_count ]== 'r' )&& strlen (* ptr )!= 0 &&
906947opt_numericsep != NULL && strlen (opt_numericsep )> 0 )
907948{
908- char * my_cell = pg_malloc (len_with_numericsep (* ptr ));
949+ char * my_cell = malloc (len_with_numericsep (* ptr ));
909950
951+ if (!my_cell )
952+ {
953+ fprintf (stderr ,_ ("out of memory\n" ));
954+ exit (EXIT_FAILURE );
955+ }
910956strcpy (my_cell ,* ptr );
911957format_numericsep (my_cell ,opt_numericsep );
912958html_escaped_print (my_cell ,fout );
@@ -1600,7 +1646,12 @@ printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, FILE *f
16001646exit (EXIT_FAILURE );
16011647}
16021648
1603- footers [0 ]= pg_malloc (100 );
1649+ footers [0 ]= malloc (100 );
1650+ if (!footers [0 ])
1651+ {
1652+ fprintf (stderr ,_ ("out of memory\n" ));
1653+ exit (EXIT_FAILURE );
1654+ }
16041655if (PQntuples (result )== 1 )
16051656snprintf (footers [0 ],100 ,_ ("(1 row)" ));
16061657else