Skip to content

Commit f86c63a

Browse files
committed
Reverse pg_malloc patch because psql/print.c is used in scripts files
that don't have pg_malloc.
1 parent 8c9393c commit f86c63a

File tree

1 file changed

+62
-11
lines changed

1 file changed

+62
-11
lines changed

src/bin/psql/print.c

Lines changed: 62 additions & 11 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.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)
7777
if (digits_before_sep == 0)
7878
new_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

8287
for (i=0, j=0; ; i++, j++)
8388
{
@@ -162,8 +167,13 @@ print_unaligned_text(const char *title, const char *const *headers,
162167
if ((opt_align[i % col_count] == 'r') && strlen(*ptr) > 0 &&
163168
opt_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+
}
167177
strcpy(my_cell, *ptr);
168178
format_numericsep(my_cell, opt_numericsep);
169179
fputs(my_cell, fout);
@@ -239,8 +249,13 @@ print_unaligned_vertical(const char *title, const char *const *headers,
239249
if ((opt_align[i % col_count] == 'r') && strlen(*ptr) != 0 &&
240250
opt_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+
}
244259
strcpy(my_cell, *ptr);
245260
format_numericsep(my_cell, opt_numericsep);
246261
fputs(my_cell, fout);
@@ -467,8 +482,13 @@ print_aligned_text(const char *title, const char *const *headers,
467482
{
468483
if (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+
}
472492
strcpy(my_cell, *ptr);
473493
format_numericsep(my_cell, opt_numericsep);
474494
fprintf(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,
614634
fprintf(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+
}
618643
divider[0] = '\0';
619644
if (opt_border == 2)
620645
strcat(divider, "+-");
@@ -636,9 +661,15 @@ print_aligned_vertical(const char *title, const char *const *headers,
636661
{
637662
if (!opt_barebones)
638663
{
639-
char *record_str = pg_malloc(32);
664+
char *record_str = malloc(32);
640665
size_t record_str_len;
641666

667+
if (!record_str)
668+
{
669+
fprintf(stderr, _("out of memory\n"));
670+
exit(EXIT_FAILURE);
671+
}
672+
642673
if (opt_border == 0)
643674
snprintf(record_str, 32, "* Record %d", record++);
644675
else
@@ -678,8 +709,13 @@ print_aligned_vertical(const char *title, const char *const *headers,
678709
fputs(" ", 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+
}
683719
strcpy(my_cell, *ptr);
684720
if ((opt_align[i % col_count] == 'r') && strlen(*ptr) != 0 &&
685721
opt_numericsep != NULL && strlen(opt_numericsep) > 0)
@@ -819,8 +855,13 @@ print_html_text(const char *title, const char *const *headers,
819855
else if ((opt_align[i % col_count] == 'r') && strlen(*ptr) != 0 &&
820856
opt_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+
}
824865
strcpy(my_cell, *ptr);
825866
format_numericsep(my_cell, opt_numericsep);
826867
html_escaped_print(my_cell, fout);
@@ -905,8 +946,13 @@ print_html_vertical(const char *title, const char *const *headers,
905946
else if ((opt_align[i % col_count] == 'r') && strlen(*ptr) != 0 &&
906947
opt_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+
}
910956
strcpy(my_cell, *ptr);
911957
format_numericsep(my_cell, opt_numericsep);
912958
html_escaped_print(my_cell, fout);
@@ -1600,7 +1646,12 @@ printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, FILE *f
16001646
exit(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+
}
16041655
if (PQntuples(result) == 1)
16051656
snprintf(footers[0], 100, _("(1 row)"));
16061657
else

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy