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

Commit8c9393c

Browse files
committed
Use failure-safe pg_malloc consistently in psql/print.c.
1 parent6e1004f commit8c9393c

File tree

1 file changed

+11
-62
lines changed

1 file changed

+11
-62
lines changed

‎src/bin/psql/print.c

Lines changed: 11 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
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)
7777
if (digits_before_sep==0)
7878
new_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

8782
for (i=0,j=0; ;i++,j++)
8883
{
@@ -167,13 +162,8 @@ print_unaligned_text(const char *title, const char *const *headers,
167162
if ((opt_align[i %col_count]=='r')&&strlen(*ptr)>0&&
168163
opt_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-
}
177167
strcpy(my_cell,*ptr);
178168
format_numericsep(my_cell,opt_numericsep);
179169
fputs(my_cell,fout);
@@ -249,13 +239,8 @@ print_unaligned_vertical(const char *title, const char *const *headers,
249239
if ((opt_align[i %col_count]=='r')&&strlen(*ptr)!=0&&
250240
opt_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-
}
259244
strcpy(my_cell,*ptr);
260245
format_numericsep(my_cell,opt_numericsep);
261246
fputs(my_cell,fout);
@@ -482,13 +467,8 @@ print_aligned_text(const char *title, const char *const *headers,
482467
{
483468
if (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-
}
492472
strcpy(my_cell,*ptr);
493473
format_numericsep(my_cell,opt_numericsep);
494474
fprintf(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,
634614
fprintf(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);
643618
divider[0]='\0';
644619
if (opt_border==2)
645620
strcat(divider,"+-");
@@ -661,15 +636,9 @@ print_aligned_vertical(const char *title, const char *const *headers,
661636
{
662637
if (!opt_barebones)
663638
{
664-
char*record_str=malloc(32);
639+
char*record_str=pg_malloc(32);
665640
size_trecord_str_len;
666641

667-
if (!record_str)
668-
{
669-
fprintf(stderr,_("out of memory\n"));
670-
exit(EXIT_FAILURE);
671-
}
672-
673642
if (opt_border==0)
674643
snprintf(record_str,32,"* Record %d",record++);
675644
else
@@ -709,13 +678,8 @@ print_aligned_vertical(const char *title, const char *const *headers,
709678
fputs(" ",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-
}
719683
strcpy(my_cell,*ptr);
720684
if ((opt_align[i %col_count]=='r')&&strlen(*ptr)!=0&&
721685
opt_numericsep!=NULL&&strlen(opt_numericsep)>0)
@@ -855,13 +819,8 @@ print_html_text(const char *title, const char *const *headers,
855819
elseif ((opt_align[i %col_count]=='r')&&strlen(*ptr)!=0&&
856820
opt_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-
}
865824
strcpy(my_cell,*ptr);
866825
format_numericsep(my_cell,opt_numericsep);
867826
html_escaped_print(my_cell,fout);
@@ -946,13 +905,8 @@ print_html_vertical(const char *title, const char *const *headers,
946905
elseif ((opt_align[i %col_count]=='r')&&strlen(*ptr)!=0&&
947906
opt_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-
}
956910
strcpy(my_cell,*ptr);
957911
format_numericsep(my_cell,opt_numericsep);
958912
html_escaped_print(my_cell,fout);
@@ -1646,12 +1600,7 @@ printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, FILE *f
16461600
exit(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);
16551604
if (PQntuples(result)==1)
16561605
snprintf(footers[0],100,_("(1 row)"));
16571606
else

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp