Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
postgres-lambda-diff
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jakob Huber
postgres-lambda-diff
Commits
cff9c574
Commit
cff9c574
authored
19 years ago
by
Bruce Momjian
Browse files
Options
Downloads
Patches
Plain Diff
Fix malloc length for new numeric separator patch.
Centralize malloc into function.
parent
c3f1b0f4
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/bin/psql/print.c
+26
-62
26 additions, 62 deletions
src/bin/psql/print.c
with
26 additions
and
62 deletions
src/bin/psql/print.c
+
26
−
62
View file @
cff9c574
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
*
*
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
* Copyright (c) 2000-2005, PostgreSQL Global Development Group
*
*
* $PostgreSQL: pgsql/src/bin/psql/print.c,v 1.6
3
2005/07/1
0 15:53:42
momjian Exp $
* $PostgreSQL: pgsql/src/bin/psql/print.c,v 1.6
4
2005/07/1
4 06:46:17
momjian Exp $
*/
*/
#include
"postgres_fe.h"
#include
"postgres_fe.h"
#include
"common.h"
#include
"common.h"
...
@@ -29,6 +29,20 @@
...
@@ -29,6 +29,20 @@
#include
"mbprint.h"
#include
"mbprint.h"
static
void
*
pg_local_malloc
(
size_t
size
)
{
void
*
tmp
;
tmp
=
malloc
(
size
);
if
(
!
tmp
)
{
psql_error
(
"out of memory
\n
"
);
exit
(
EXIT_FAILURE
);
}
return
tmp
;
}
static
int
static
int
num_numericseps
(
const
char
*
my_str
)
num_numericseps
(
const
char
*
my_str
)
{
{
...
@@ -46,6 +60,7 @@ num_numericseps(const char *my_str)
...
@@ -46,6 +60,7 @@ num_numericseps(const char *my_str)
else
else
return
int_len
/
3
-
1
;
/* no leading separator */
return
int_len
/
3
-
1
;
/* no leading separator */
}
}
static
int
static
int
len_with_numericsep
(
const
char
*
my_str
)
len_with_numericsep
(
const
char
*
my_str
)
{
{
...
@@ -77,12 +92,7 @@ format_numericsep(char *my_str, char *numericsep)
...
@@ -77,12 +92,7 @@ format_numericsep(char *my_str, char *numericsep)
if
(
digits_before_sep
==
0
)
if
(
digits_before_sep
==
0
)
new_len
--
;
/* no leading separator */
new_len
--
;
/* no leading separator */
new_str
=
malloc
(
new_len
);
new_str
=
pg_local_malloc
(
new_len
+
1
);
if
(
!
new_str
)
{
fprintf
(
stderr
,
_
(
"out of memory
\n
"
));
exit
(
EXIT_FAILURE
);
}
for
(
i
=
0
,
j
=
0
;
;
i
++
,
j
++
)
for
(
i
=
0
,
j
=
0
;
;
i
++
,
j
++
)
{
{
...
@@ -167,13 +177,8 @@ print_unaligned_text(const char *title, const char *const *headers,
...
@@ -167,13 +177,8 @@ print_unaligned_text(const char *title, const char *const *headers,
if
((
opt_align
[
i
%
col_count
]
==
'r'
)
&&
strlen
(
*
ptr
)
>
0
&&
if
((
opt_align
[
i
%
col_count
]
==
'r'
)
&&
strlen
(
*
ptr
)
>
0
&&
opt_numericsep
!=
NULL
&&
strlen
(
opt_numericsep
)
>
0
)
opt_numericsep
!=
NULL
&&
strlen
(
opt_numericsep
)
>
0
)
{
{
char
*
my_cell
=
malloc
(
len_with_numericsep
(
*
ptr
));
char
*
my_cell
=
pg_local_
malloc
(
len_with_numericsep
(
*
ptr
)
+
1
);
if
(
!
my_cell
)
{
fprintf
(
stderr
,
_
(
"out of memory
\n
"
));
exit
(
EXIT_FAILURE
);
}
strcpy
(
my_cell
,
*
ptr
);
strcpy
(
my_cell
,
*
ptr
);
format_numericsep
(
my_cell
,
opt_numericsep
);
format_numericsep
(
my_cell
,
opt_numericsep
);
fputs
(
my_cell
,
fout
);
fputs
(
my_cell
,
fout
);
...
@@ -249,13 +254,8 @@ print_unaligned_vertical(const char *title, const char *const *headers,
...
@@ -249,13 +254,8 @@ print_unaligned_vertical(const char *title, const char *const *headers,
if
((
opt_align
[
i
%
col_count
]
==
'r'
)
&&
strlen
(
*
ptr
)
!=
0
&&
if
((
opt_align
[
i
%
col_count
]
==
'r'
)
&&
strlen
(
*
ptr
)
!=
0
&&
opt_numericsep
!=
NULL
&&
strlen
(
opt_numericsep
)
>
0
)
opt_numericsep
!=
NULL
&&
strlen
(
opt_numericsep
)
>
0
)
{
{
char
*
my_cell
=
malloc
(
len_with_numericsep
(
*
ptr
));
char
*
my_cell
=
pg_local_
malloc
(
len_with_numericsep
(
*
ptr
)
+
1
);
if
(
!
my_cell
)
{
fprintf
(
stderr
,
_
(
"out of memory
\n
"
));
exit
(
EXIT_FAILURE
);
}
strcpy
(
my_cell
,
*
ptr
);
strcpy
(
my_cell
,
*
ptr
);
format_numericsep
(
my_cell
,
opt_numericsep
);
format_numericsep
(
my_cell
,
opt_numericsep
);
fputs
(
my_cell
,
fout
);
fputs
(
my_cell
,
fout
);
...
@@ -482,13 +482,8 @@ print_aligned_text(const char *title, const char *const *headers,
...
@@ -482,13 +482,8 @@ print_aligned_text(const char *title, const char *const *headers,
{
{
if
(
strlen
(
*
ptr
)
>
0
&&
opt_numericsep
!=
NULL
&&
strlen
(
opt_numericsep
)
>
0
)
if
(
strlen
(
*
ptr
)
>
0
&&
opt_numericsep
!=
NULL
&&
strlen
(
opt_numericsep
)
>
0
)
{
{
char
*
my_cell
=
malloc
(
cell_w
[
i
]);
char
*
my_cell
=
pg_local_
malloc
(
cell_w
[
i
]
+
1
);
if
(
!
my_cell
)
{
fprintf
(
stderr
,
_
(
"out of memory
\n
"
));
exit
(
EXIT_FAILURE
);
}
strcpy
(
my_cell
,
*
ptr
);
strcpy
(
my_cell
,
*
ptr
);
format_numericsep
(
my_cell
,
opt_numericsep
);
format_numericsep
(
my_cell
,
opt_numericsep
);
fprintf
(
fout
,
"%*s%s"
,
widths
[
i
%
col_count
]
-
cell_w
[
i
],
""
,
my_cell
);
fprintf
(
fout
,
"%*s%s"
,
widths
[
i
%
col_count
]
-
cell_w
[
i
],
""
,
my_cell
);
...
@@ -634,12 +629,7 @@ print_aligned_vertical(const char *title, const char *const *headers,
...
@@ -634,12 +629,7 @@ print_aligned_vertical(const char *title, const char *const *headers,
fprintf
(
fout
,
"%s
\n
"
,
title
);
fprintf
(
fout
,
"%s
\n
"
,
title
);
/* make horizontal border */
/* make horizontal border */
divider
=
malloc
(
hwidth
+
dwidth
+
10
);
divider
=
pg_local_malloc
(
hwidth
+
dwidth
+
10
);
if
(
!
divider
)
{
fprintf
(
stderr
,
_
(
"out of memory
\n
"
));
exit
(
EXIT_FAILURE
);
}
divider
[
0
]
=
'\0'
;
divider
[
0
]
=
'\0'
;
if
(
opt_border
==
2
)
if
(
opt_border
==
2
)
strcat
(
divider
,
"+-"
);
strcat
(
divider
,
"+-"
);
...
@@ -661,15 +651,9 @@ print_aligned_vertical(const char *title, const char *const *headers,
...
@@ -661,15 +651,9 @@ print_aligned_vertical(const char *title, const char *const *headers,
{
{
if
(
!
opt_barebones
)
if
(
!
opt_barebones
)
{
{
char
*
record_str
=
malloc
(
32
);
char
*
record_str
=
pg_local_
malloc
(
32
);
size_t
record_str_len
;
size_t
record_str_len
;
if
(
!
record_str
)
{
fprintf
(
stderr
,
_
(
"out of memory
\n
"
));
exit
(
EXIT_FAILURE
);
}
if
(
opt_border
==
0
)
if
(
opt_border
==
0
)
snprintf
(
record_str
,
32
,
"* Record %d"
,
record
++
);
snprintf
(
record_str
,
32
,
"* Record %d"
,
record
++
);
else
else
...
@@ -709,13 +693,8 @@ print_aligned_vertical(const char *title, const char *const *headers,
...
@@ -709,13 +693,8 @@ print_aligned_vertical(const char *title, const char *const *headers,
fputs
(
" "
,
fout
);
fputs
(
" "
,
fout
);
{
{
char
*
my_cell
=
malloc
(
cell_w
[
i
]);
char
*
my_cell
=
pg_local_
malloc
(
cell_w
[
i
]
+
1
);
if
(
!
my_cell
)
{
fprintf
(
stderr
,
_
(
"out of memory
\n
"
));
exit
(
EXIT_FAILURE
);
}
strcpy
(
my_cell
,
*
ptr
);
strcpy
(
my_cell
,
*
ptr
);
if
((
opt_align
[
i
%
col_count
]
==
'r'
)
&&
strlen
(
*
ptr
)
!=
0
&&
if
((
opt_align
[
i
%
col_count
]
==
'r'
)
&&
strlen
(
*
ptr
)
!=
0
&&
opt_numericsep
!=
NULL
&&
strlen
(
opt_numericsep
)
>
0
)
opt_numericsep
!=
NULL
&&
strlen
(
opt_numericsep
)
>
0
)
...
@@ -855,13 +834,8 @@ print_html_text(const char *title, const char *const *headers,
...
@@ -855,13 +834,8 @@ print_html_text(const char *title, const char *const *headers,
else
if
((
opt_align
[
i
%
col_count
]
==
'r'
)
&&
strlen
(
*
ptr
)
!=
0
&&
else
if
((
opt_align
[
i
%
col_count
]
==
'r'
)
&&
strlen
(
*
ptr
)
!=
0
&&
opt_numericsep
!=
NULL
&&
strlen
(
opt_numericsep
)
>
0
)
opt_numericsep
!=
NULL
&&
strlen
(
opt_numericsep
)
>
0
)
{
{
char
*
my_cell
=
malloc
(
len_with_numericsep
(
*
ptr
));
char
*
my_cell
=
pg_local_
malloc
(
len_with_numericsep
(
*
ptr
)
+
1
);
if
(
!
my_cell
)
{
fprintf
(
stderr
,
_
(
"out of memory
\n
"
));
exit
(
EXIT_FAILURE
);
}
strcpy
(
my_cell
,
*
ptr
);
strcpy
(
my_cell
,
*
ptr
);
format_numericsep
(
my_cell
,
opt_numericsep
);
format_numericsep
(
my_cell
,
opt_numericsep
);
html_escaped_print
(
my_cell
,
fout
);
html_escaped_print
(
my_cell
,
fout
);
...
@@ -946,13 +920,8 @@ print_html_vertical(const char *title, const char *const *headers,
...
@@ -946,13 +920,8 @@ print_html_vertical(const char *title, const char *const *headers,
else
if
((
opt_align
[
i
%
col_count
]
==
'r'
)
&&
strlen
(
*
ptr
)
!=
0
&&
else
if
((
opt_align
[
i
%
col_count
]
==
'r'
)
&&
strlen
(
*
ptr
)
!=
0
&&
opt_numericsep
!=
NULL
&&
strlen
(
opt_numericsep
)
>
0
)
opt_numericsep
!=
NULL
&&
strlen
(
opt_numericsep
)
>
0
)
{
{
char
*
my_cell
=
malloc
(
len_with_numericsep
(
*
ptr
));
char
*
my_cell
=
pg_local_
malloc
(
len_with_numericsep
(
*
ptr
)
+
1
);
if
(
!
my_cell
)
{
fprintf
(
stderr
,
_
(
"out of memory
\n
"
));
exit
(
EXIT_FAILURE
);
}
strcpy
(
my_cell
,
*
ptr
);
strcpy
(
my_cell
,
*
ptr
);
format_numericsep
(
my_cell
,
opt_numericsep
);
format_numericsep
(
my_cell
,
opt_numericsep
);
html_escaped_print
(
my_cell
,
fout
);
html_escaped_print
(
my_cell
,
fout
);
...
@@ -1646,12 +1615,7 @@ printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, FILE *f
...
@@ -1646,12 +1615,7 @@ printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, FILE *f
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
footers
[
0
]
=
malloc
(
100
);
footers
[
0
]
=
pg_local_malloc
(
100
);
if
(
!
footers
[
0
])
{
fprintf
(
stderr
,
_
(
"out of memory
\n
"
));
exit
(
EXIT_FAILURE
);
}
if
(
PQntuples
(
result
)
==
1
)
if
(
PQntuples
(
result
)
==
1
)
snprintf
(
footers
[
0
],
100
,
_
(
"(1 row)"
));
snprintf
(
footers
[
0
],
100
,
_
(
"(1 row)"
));
else
else
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment