33 *
44 * Copyright (c) 2000-2003, PostgreSQL Global Development Group
55 *
6- * $PostgreSQL: pgsql/src/bin/psql/print.c,v 1.45 2004/01/2419:38:49 neilc Exp $
6+ * $PostgreSQL: pgsql/src/bin/psql/print.c,v 1.46 2004/01/2420:43:26 neilc Exp $
77 */
88#include "postgres_fe.h"
99#include "common.h"
@@ -224,8 +224,19 @@ print_aligned_text(const char *title, const char *const * headers,
224224
225225if (col_count > 0 )
226226{
227- widths = xcalloc (col_count ,sizeof (* widths ));
228- head_w = xcalloc (col_count ,sizeof (* head_w ));
227+ widths = calloc (col_count ,sizeof (* widths ));
228+ if (!widths )
229+ {
230+ perror ("calloc" );
231+ exit (EXIT_FAILURE );
232+ }
233+
234+ head_w = calloc (col_count ,sizeof (* head_w ));
235+ if (!head_w )
236+ {
237+ perror ("calloc" );
238+ exit (EXIT_FAILURE );
239+ }
229240}
230241else
231242{
@@ -239,7 +250,12 @@ print_aligned_text(const char *title, const char *const * headers,
239250
240251if (cell_count > 0 )
241252{
242- cell_w = xcalloc (cell_count ,sizeof (* cell_w ));
253+ cell_w = calloc (cell_count ,sizeof (* cell_w ));
254+ if (!cell_w )
255+ {
256+ perror ("calloc" );
257+ exit (EXIT_FAILURE );
258+ }
243259}
244260else
245261cell_w = NULL ;
@@ -411,7 +427,12 @@ print_aligned_vertical(const char *title, const char *const * headers,
411427col_count ++ ;
412428if (col_count > 0 )
413429{
414- head_w = xcalloc (col_count ,sizeof (* head_w ));
430+ head_w = calloc (col_count ,sizeof (* head_w ));
431+ if (!head_w )
432+ {
433+ perror ("calloc" );
434+ exit (EXIT_FAILURE );
435+ }
415436}
416437else
417438head_w = NULL ;
@@ -430,7 +451,12 @@ print_aligned_vertical(const char *title, const char *const * headers,
430451
431452if (cell_count > 0 )
432453{
433- cell_w = xcalloc (cell_count ,sizeof (* cell_w ));
454+ cell_w = calloc (cell_count ,sizeof (* cell_w ));
455+ if (!cell_w )
456+ {
457+ perror ("calloc" );
458+ exit (EXIT_FAILURE );
459+ }
434460}
435461else
436462cell_w = NULL ;
@@ -449,7 +475,12 @@ print_aligned_vertical(const char *title, const char *const * headers,
449475fprintf (fout ,"%s\n" ,title );
450476
451477/* make horizontal border */
452- divider = xmalloc (hwidth + dwidth + 10 );
478+ divider = malloc (hwidth + dwidth + 10 );
479+ if (!divider )
480+ {
481+ perror ("malloc" );
482+ exit (EXIT_FAILURE );
483+ }
453484divider [0 ]= '\0' ;
454485if (opt_border == 2 )
455486strcat (divider ,"+-" );
@@ -471,9 +502,15 @@ print_aligned_vertical(const char *title, const char *const * headers,
471502{
472503if (!opt_barebones )
473504{
474- char * record_str = xmalloc (32 );
505+ char * record_str = malloc (32 );
475506size_t record_str_len ;
476507
508+ if (!record_str )
509+ {
510+ perror ("malloc" );
511+ exit (EXIT_FAILURE );
512+ }
513+
477514if (opt_border == 0 )
478515snprintf (record_str ,32 ,"* Record %d" ,record ++ );
479516else
@@ -484,7 +521,13 @@ print_aligned_vertical(const char *title, const char *const * headers,
484521fprintf (fout ,"%.*s%s\n" ,opt_border ,divider ,record_str );
485522else
486523{
487- char * div_copy = xstrdup (divider );
524+ char * div_copy = strdup (divider );
525+
526+ if (!div_copy )
527+ {
528+ perror ("malloc" );
529+ exit (EXIT_FAILURE );
530+ }
488531
489532strncpy (div_copy + opt_border ,record_str ,record_str_len );
490533fprintf (fout ,"%s\n" ,div_copy );
@@ -1098,14 +1141,24 @@ printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout)
10981141
10991142nfields = PQnfields (result );
11001143
1101- headers = xcalloc (nfields + 1 ,sizeof (* headers ));
1144+ headers = calloc (nfields + 1 ,sizeof (* headers ));
1145+ if (!headers )
1146+ {
1147+ perror ("calloc" );
1148+ exit (EXIT_FAILURE );
1149+ }
11021150
11031151for (i = 0 ;i < nfields ;i ++ )
11041152headers [i ]= mbvalidate (PQfname (result ,i ),opt -> topt .encoding );
11051153
11061154/* set cells */
11071155
1108- cells = xcalloc (nfields * PQntuples (result )+ 1 ,sizeof (* cells ));
1156+ cells = calloc (nfields * PQntuples (result )+ 1 ,sizeof (* cells ));
1157+ if (!cells )
1158+ {
1159+ perror ("calloc" );
1160+ exit (EXIT_FAILURE );
1161+ }
11091162
11101163for (i = 0 ;i < nfields * PQntuples (result );i ++ )
11111164{
@@ -1121,9 +1174,14 @@ printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout)
11211174footers = opt -> footers ;
11221175else if (!opt -> topt .expanded && opt -> default_footer )
11231176{
1124- footers = xcalloc (2 ,sizeof (* footers ));
1177+ footers = calloc (2 ,sizeof (* footers ));
1178+ if (!footers )
1179+ {
1180+ perror ("calloc" );
1181+ exit (EXIT_FAILURE );
1182+ }
11251183
1126- footers [0 ]= xmalloc (100 );
1184+ footers [0 ]= malloc (100 );
11271185if (PQntuples (result )== 1 )
11281186snprintf (footers [0 ],100 ,gettext ("(1 row)" ));
11291187else
@@ -1134,7 +1192,12 @@ printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout)
11341192
11351193/* set alignment */
11361194
1137- align = xcalloc (nfields + 1 ,sizeof (* align ));
1195+ align = calloc (nfields + 1 ,sizeof (* align ));
1196+ if (!align )
1197+ {
1198+ perror ("calloc" );
1199+ exit (EXIT_FAILURE );
1200+ }
11381201
11391202for (i = 0 ;i < nfields ;i ++ )
11401203{