3
3
*
4
4
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
5
5
*
6
- * $PostgreSQL: pgsql/src/bin/psql/print.c,v 1.45 2004/01/24 19:38:49 neilc Exp $
6
+ * $PostgreSQL: pgsql/src/bin/psql/print.c,v 1.46 2004/01/24 20:43:26 neilc Exp $
7
7
*/
8
8
#include "postgres_fe.h"
9
9
#include "common.h"
@@ -224,8 +224,19 @@ print_aligned_text(const char *title, const char *const * headers,
224
224
225
225
if (col_count > 0)
226
226
{
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
+ }
229
240
}
230
241
else
231
242
{
@@ -239,7 +250,12 @@ print_aligned_text(const char *title, const char *const * headers,
239
250
240
251
if (cell_count > 0)
241
252
{
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
+ }
243
259
}
244
260
else
245
261
cell_w = NULL;
@@ -411,7 +427,12 @@ print_aligned_vertical(const char *title, const char *const * headers,
411
427
col_count++;
412
428
if (col_count > 0)
413
429
{
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
+ }
415
436
}
416
437
else
417
438
head_w = NULL;
@@ -430,7 +451,12 @@ print_aligned_vertical(const char *title, const char *const * headers,
430
451
431
452
if (cell_count > 0)
432
453
{
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
+ }
434
460
}
435
461
else
436
462
cell_w = NULL;
@@ -449,7 +475,12 @@ print_aligned_vertical(const char *title, const char *const * headers,
449
475
fprintf(fout, "%s\n", title);
450
476
451
477
/* 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
+ }
453
484
divider[0] = '\0';
454
485
if (opt_border == 2)
455
486
strcat(divider, "+-");
@@ -471,9 +502,15 @@ print_aligned_vertical(const char *title, const char *const * headers,
471
502
{
472
503
if (!opt_barebones)
473
504
{
474
- char *record_str = xmalloc (32);
505
+ char *record_str = malloc (32);
475
506
size_t record_str_len;
476
507
508
+ if (!record_str)
509
+ {
510
+ perror("malloc");
511
+ exit(EXIT_FAILURE);
512
+ }
513
+
477
514
if (opt_border == 0)
478
515
snprintf(record_str, 32, "* Record %d", record++);
479
516
else
@@ -484,7 +521,13 @@ print_aligned_vertical(const char *title, const char *const * headers,
484
521
fprintf(fout, "%.*s%s\n", opt_border, divider, record_str);
485
522
else
486
523
{
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
+ }
488
531
489
532
strncpy(div_copy + opt_border, record_str, record_str_len);
490
533
fprintf(fout, "%s\n", div_copy);
@@ -1098,14 +1141,24 @@ printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout)
1098
1141
1099
1142
nfields = PQnfields(result);
1100
1143
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
+ }
1102
1150
1103
1151
for (i = 0; i < nfields; i++)
1104
1152
headers[i] = mbvalidate(PQfname(result, i), opt->topt.encoding);
1105
1153
1106
1154
/* set cells */
1107
1155
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
+ }
1109
1162
1110
1163
for (i = 0; i < nfields * PQntuples(result); i++)
1111
1164
{
@@ -1121,9 +1174,14 @@ printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout)
1121
1174
footers = opt->footers;
1122
1175
else if (!opt->topt.expanded && opt->default_footer)
1123
1176
{
1124
- footers = xcalloc(2, sizeof(*footers));
1177
+ footers = calloc(2, sizeof(*footers));
1178
+ if (!footers)
1179
+ {
1180
+ perror("calloc");
1181
+ exit(EXIT_FAILURE);
1182
+ }
1125
1183
1126
- footers[0] = xmalloc (100);
1184
+ footers[0] = malloc (100);
1127
1185
if (PQntuples(result) == 1)
1128
1186
snprintf(footers[0], 100, gettext("(1 row)"));
1129
1187
else
@@ -1134,7 +1192,12 @@ printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout)
1134
1192
1135
1193
/* set alignment */
1136
1194
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
+ }
1138
1201
1139
1202
for (i = 0; i < nfields; i++)
1140
1203
{
0 commit comments