Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6f046b9

Browse files
author
Neil Conway
committed
Revert the change to print.c, as this breaks src/bin/scripts. The proper
way to fix this is probably implementing safe memory handling functionsonce in a static lib and then using that in the various client apps,but for the moment I've just reverted the change to un-break the tree.
1 parentd77b63b commit6f046b9

File tree

1 file changed

+77
-14
lines changed

1 file changed

+77
-14
lines changed

‎src/bin/psql/print.c

Lines changed: 77 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
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

225225
if (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
}
230241
else
231242
{
@@ -239,7 +250,12 @@ print_aligned_text(const char *title, const char *const * headers,
239250

240251
if (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
}
244260
else
245261
cell_w=NULL;
@@ -411,7 +427,12 @@ print_aligned_vertical(const char *title, const char *const * headers,
411427
col_count++;
412428
if (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
}
416437
else
417438
head_w=NULL;
@@ -430,7 +451,12 @@ print_aligned_vertical(const char *title, const char *const * headers,
430451

431452
if (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
}
435461
else
436462
cell_w=NULL;
@@ -449,7 +475,12 @@ print_aligned_vertical(const char *title, const char *const * headers,
449475
fprintf(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+
}
453484
divider[0]='\0';
454485
if (opt_border==2)
455486
strcat(divider,"+-");
@@ -471,9 +502,15 @@ print_aligned_vertical(const char *title, const char *const * headers,
471502
{
472503
if (!opt_barebones)
473504
{
474-
char*record_str=xmalloc(32);
505+
char*record_str=malloc(32);
475506
size_trecord_str_len;
476507

508+
if (!record_str)
509+
{
510+
perror("malloc");
511+
exit(EXIT_FAILURE);
512+
}
513+
477514
if (opt_border==0)
478515
snprintf(record_str,32,"* Record %d",record++);
479516
else
@@ -484,7 +521,13 @@ print_aligned_vertical(const char *title, const char *const * headers,
484521
fprintf(fout,"%.*s%s\n",opt_border,divider,record_str);
485522
else
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

489532
strncpy(div_copy+opt_border,record_str,record_str_len);
490533
fprintf(fout,"%s\n",div_copy);
@@ -1098,14 +1141,24 @@ printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout)
10981141

10991142
nfields=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

11031151
for (i=0;i<nfields;i++)
11041152
headers[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

11101163
for (i=0;i<nfields*PQntuples(result);i++)
11111164
{
@@ -1121,9 +1174,14 @@ printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout)
11211174
footers=opt->footers;
11221175
elseif (!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);
11271185
if (PQntuples(result)==1)
11281186
snprintf(footers[0],100,gettext("(1 row)"));
11291187
else
@@ -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

11391202
for (i=0;i<nfields;i++)
11401203
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp