Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
6a2869f6
Commit
6a2869f6
authored
Sep 16, 2004
by
Neil Conway
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix a read of uninitialized memory in array_out(). Perform some minor
cosmetic code cleanup at the same time.
parent
d1b0d965
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
25 deletions
+34
-25
src/backend/utils/adt/arrayfuncs.c
src/backend/utils/adt/arrayfuncs.c
+25
-16
src/backend/utils/adt/arrayutils.c
src/backend/utils/adt/arrayutils.c
+5
-5
src/include/utils/array.h
src/include/utils/array.h
+4
-4
No files found.
src/backend/utils/adt/arrayfuncs.c
View file @
6a2869f6
...
...
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/arrayfuncs.c,v 1.11
1 2004/09/02 20:05:40 tgl
Exp $
* $PostgreSQL: pgsql/src/backend/utils/adt/arrayfuncs.c,v 1.11
2 2004/09/16 03:15:52 neilc
Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -896,7 +896,7 @@ array_out(PG_FUNCTION_ARGS)
k
,
indx
[
MAXDIM
];
int
ndim
,
*
dim
,
*
dim
s
,
*
lb
;
ArrayMetaState
*
my_extra
;
...
...
@@ -937,9 +937,9 @@ array_out(PG_FUNCTION_ARGS)
typioparam
=
my_extra
->
typioparam
;
ndim
=
ARR_NDIM
(
v
);
dim
=
ARR_DIMS
(
v
);
dim
s
=
ARR_DIMS
(
v
);
lb
=
ARR_LBOUND
(
v
);
nitems
=
ArrayGetNItems
(
ndim
,
dim
);
nitems
=
ArrayGetNItems
(
ndim
,
dim
s
);
if
(
nitems
==
0
)
{
...
...
@@ -968,11 +968,12 @@ array_out(PG_FUNCTION_ARGS)
values
=
(
char
**
)
palloc
(
nitems
*
sizeof
(
char
*
));
needquotes
=
(
bool
*
)
palloc
(
nitems
*
sizeof
(
bool
));
p
=
ARR_DATA_PTR
(
v
);
overall_length
=
1
;
/* [TRH] don't forget to count \0 at end. */
overall_length
=
1
;
/* don't forget to count \0 at end. */
for
(
i
=
0
;
i
<
nitems
;
i
++
)
{
Datum
itemvalue
;
bool
n
q
;
bool
n
eedquote
;
itemvalue
=
fetch_att
(
p
,
typbyval
,
typlen
);
values
[
i
]
=
DatumGetCString
(
FunctionCall3
(
&
my_extra
->
proc
,
...
...
@@ -983,28 +984,32 @@ array_out(PG_FUNCTION_ARGS)
p
=
(
char
*
)
att_align
(
p
,
typalign
);
/* count data plus backslashes; detect chars needing quotes */
nq
=
(
values
[
i
][
0
]
==
'\0'
);
/* force quotes for empty string */
for
(
tmp
=
values
[
i
];
*
tmp
;
tmp
++
)
if
(
values
[
i
][
0
]
==
'\0'
)
needquote
=
true
;
/* force quotes for empty string */
else
needquote
=
false
;
for
(
tmp
=
values
[
i
];
*
tmp
!=
'\0'
;
tmp
++
)
{
char
ch
=
*
tmp
;
overall_length
+=
1
;
if
(
ch
==
'"'
||
ch
==
'\\'
)
{
n
q
=
true
;
n
eedquote
=
true
;
#ifndef TCL_ARRAYS
overall_length
+=
1
;
#endif
}
else
if
(
ch
==
'{'
||
ch
==
'}'
||
ch
==
typdelim
||
isspace
((
unsigned
char
)
ch
))
n
q
=
true
;
n
eedquote
=
true
;
}
needquotes
[
i
]
=
n
q
;
needquotes
[
i
]
=
n
eedquote
;
/* Count the pair of double quotes, if needed */
if
(
n
q
)
if
(
n
eedquote
)
overall_length
+=
2
;
/* and the comma */
...
...
@@ -1014,7 +1019,10 @@ array_out(PG_FUNCTION_ARGS)
/*
* count total number of curly braces in output string
*/
for
(
i
=
j
=
0
,
k
=
1
;
i
<
ndim
;
k
*=
dim
[
i
++
],
j
+=
k
);
for
(
i
=
j
=
0
,
k
=
1
;
i
<
ndim
;
i
++
)
k
*=
dims
[
i
],
j
+=
k
;
dims_str
[
0
]
=
'\0'
;
/* add explicit dimensions if required */
if
(
needdims
)
...
...
@@ -1023,7 +1031,7 @@ array_out(PG_FUNCTION_ARGS)
for
(
i
=
0
;
i
<
ndim
;
i
++
)
{
sprintf
(
ptr
,
"[%d:%d]"
,
lb
[
i
],
lb
[
i
]
+
dim
[
i
]
-
1
);
sprintf
(
ptr
,
"[%d:%d]"
,
lb
[
i
],
lb
[
i
]
+
dim
s
[
i
]
-
1
);
ptr
+=
strlen
(
ptr
);
}
*
ptr
++
=
*
ASSGN
;
...
...
@@ -1039,7 +1047,8 @@ array_out(PG_FUNCTION_ARGS)
if
(
needdims
)
APPENDSTR
(
dims_str
);
APPENDCHAR
(
'{'
);
for
(
i
=
0
;
i
<
ndim
;
indx
[
i
++
]
=
0
);
for
(
i
=
0
;
i
<
ndim
;
i
++
)
indx
[
i
]
=
0
;
j
=
0
;
k
=
0
;
do
...
...
@@ -1071,7 +1080,7 @@ array_out(PG_FUNCTION_ARGS)
for
(
i
=
ndim
-
1
;
i
>=
0
;
i
--
)
{
indx
[
i
]
=
(
indx
[
i
]
+
1
)
%
dim
[
i
];
indx
[
i
]
=
(
indx
[
i
]
+
1
)
%
dim
s
[
i
];
if
(
indx
[
i
])
{
APPENDCHAR
(
typdelim
);
...
...
src/backend/utils/adt/arrayutils.c
View file @
6a2869f6
...
...
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/arrayutils.c,v 1.1
6 2004/08/29 04:12:51 momjian
Exp $
* $PostgreSQL: pgsql/src/backend/utils/adt/arrayutils.c,v 1.1
7 2004/09/16 03:15:52 neilc
Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -50,16 +50,16 @@ ArrayGetOffset0(int n, int *tup, int *scale)
/* Convert array dimensions into number of elements */
int
ArrayGetNItems
(
int
n
,
int
*
a
)
ArrayGetNItems
(
int
n
dim
,
int
*
dims
)
{
int
i
,
ret
;
if
(
n
<=
0
)
if
(
n
dim
<=
0
)
return
0
;
ret
=
1
;
for
(
i
=
0
;
i
<
n
;
i
++
)
ret
*=
a
[
i
];
for
(
i
=
0
;
i
<
n
dim
;
i
++
)
ret
*=
dims
[
i
];
return
ret
;
}
...
...
src/include/utils/array.h
View file @
6a2869f6
...
...
@@ -10,7 +10,7 @@
* Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $PostgreSQL: pgsql/src/include/utils/array.h,v 1.
49 2004/08/29 04:13:10 momjian
Exp $
* $PostgreSQL: pgsql/src/include/utils/array.h,v 1.
50 2004/09/16 03:15:54 neilc
Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -81,8 +81,8 @@ typedef struct ArrayMetaState
*
* ARR_LBOUND returns a pointer to an array of array lower bounds.
*
* That is: if the third axis of an array has elements 5 through
10
, then
* ARR_DIMS(a)[2] ==
6
and ARR_LBOUND(a)[2] == 5.
* That is: if the third axis of an array has elements 5 through
8
, then
* ARR_DIMS(a)[2] ==
4
and ARR_LBOUND(a)[2] == 5.
*
* Unlike C, the default lower bound is 1.
*/
...
...
@@ -176,7 +176,7 @@ extern Datum makeMdArrayResult(ArrayBuildState *astate, int ndims,
extern
int
ArrayGetOffset
(
int
n
,
int
*
dim
,
int
*
lb
,
int
*
indx
);
extern
int
ArrayGetOffset0
(
int
n
,
int
*
tup
,
int
*
scale
);
extern
int
ArrayGetNItems
(
int
n
,
int
*
a
);
extern
int
ArrayGetNItems
(
int
n
dims
,
int
*
dims
);
extern
void
mda_get_range
(
int
n
,
int
*
span
,
int
*
st
,
int
*
endp
);
extern
void
mda_get_prod
(
int
n
,
int
*
range
,
int
*
prod
);
extern
void
mda_get_offset_values
(
int
n
,
int
*
dist
,
int
*
prod
,
int
*
span
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment