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
77f48853
Commit
77f48853
authored
25 years ago
by
Tom Lane
Browse files
Options
Downloads
Patches
Plain Diff
Fix busted TRANSLATE() code --- it coredumped due to pfree()'ing the
wrong pointer.
parent
795878d2
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/backend/utils/adt/oracle_compat.c
+53
-41
53 additions, 41 deletions
src/backend/utils/adt/oracle_compat.c
with
53 additions
and
41 deletions
src/backend/utils/adt/oracle_compat.c
+
53
−
41
View file @
77f48853
/*
* Edmund Mergl <E.Mergl@bawue.de>
*
* $Id: oracle_compat.c,v 1.2
1
2000/03/1
4 23:06:37 thomas
Exp $
* $Id: oracle_compat.c,v 1.2
2
2000/03/1
5 17:24:18 tgl
Exp $
*
*/
...
...
@@ -500,64 +500,76 @@ substr(text *string, int4 m, int4 n)
*
* Purpose:
*
* Returns string after replacing all occurences of from with
* the corresponding character in to. TRANSLATE will not remove
* characters.
* Modified to work with strings rather than single character
* for the substitution arguments.
* Modifications from Edwin Ramirez <ramirez@doc.mssm.edu>.
* Returns string after replacing all occurrences of characters in from
* with the corresponding character in to. If from is longer than to,
* occurrences of the extra characters in from are deleted.
* Improved by Edwin Ramirez <ramirez@doc.mssm.edu>.
*
********************************************************************/
text
*
translate
(
text
*
string
,
text
*
from
,
text
*
to
)
{
text
*
ret
;
char
*
ptr_ret
,
*
from_ptr
,
*
to_ptr
;
char
*
source
,
*
target
,
*
temp
,
rep
;
text
*
re
sul
t
;
char
*
from_ptr
,
*
to_ptr
;
char
*
source
,
*
target
;
int
m
,
fromlen
,
tolen
,
retlen
,
i
;
if
((
string
==
(
text
*
)
NULL
)
||
((
m
=
VARSIZE
(
string
)
-
VARHDRSZ
)
<=
0
))
return
string
;
if
(
string
==
(
text
*
)
NULL
||
from
==
(
text
*
)
NULL
||
to
==
(
text
*
)
NULL
)
return
(
text
*
)
NULL
;
target
=
(
char
*
)
palloc
(
VARSIZE
(
string
)
-
VARHDRSZ
);
source
=
VARDATA
(
string
);
temp
=
target
;
if
((
m
=
VARSIZE
(
string
)
-
VARHDRSZ
)
<=
0
)
return
string
;
fromlen
=
VARSIZE
(
from
)
-
VARHDRSZ
;
from_ptr
=
VARDATA
(
from
);
tolen
=
VARSIZE
(
to
)
-
VARHDRSZ
;
to_ptr
=
VARDATA
(
to
);
result
=
(
text
*
)
palloc
(
VARSIZE
(
string
));
source
=
VARDATA
(
string
);
target
=
VARDATA
(
result
);
retlen
=
0
;
while
(
m
--
)
while
(
m
--
>
0
)
{
rep
=
*
source
;
for
(
i
=
0
;
i
<
fromlen
;
i
++
)
{
if
(
from_ptr
[
i
]
==
*
source
)
{
if
(
i
<
tolen
)
{
rep
=
to_ptr
[
i
];
}
else
{
rep
=
0
;
}
char
rep
=
*
source
++
;
for
(
i
=
0
;
i
<
fromlen
;
i
++
)
{
if
(
from_ptr
[
i
]
==
rep
)
break
;
}
if
(
i
<
fromlen
)
{
if
(
i
<
tolen
)
{
/* substitute */
*
target
++
=
to_ptr
[
i
];
retlen
++
;
}
else
{
/* discard */
}
if
(
rep
!=
0
)
{
}
else
{
/* no match, so copy */
*
target
++
=
rep
;
retlen
++
;
}
source
++
;
}
ret
=
(
text
*
)
palloc
(
retlen
+
VARHDRSZ
);
VARSIZE
(
ret
)
=
retlen
+
VARHDRSZ
;
ptr_ret
=
VARDATA
(
ret
);
for
(
i
=
0
;
i
<
retlen
;
i
++
)
{
*
ptr_ret
++
=
temp
[
i
];
}
pfree
(
target
);
return
ret
;
}
VARSIZE
(
result
)
=
retlen
+
VARHDRSZ
;
/*
* There may be some wasted space in the result if deletions occurred,
* but it's not worth reallocating it; the function result probably
* won't live long anyway.
*/
/* EOF */
return
result
;
}
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