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
64bfa048
Commit
64bfa048
authored
28 years ago
by
Marc G. Fournier
Browse files
Options
Downloads
Patches
Plain Diff
fixes for textcat(), but headers were missing from archive :(
parent
89ad6338
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/backend/utils/adt/varlena.c
+29
-18
29 additions, 18 deletions
src/backend/utils/adt/varlena.c
with
29 additions
and
18 deletions
src/backend/utils/adt/varlena.c
+
29
−
18
View file @
64bfa048
...
...
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.
1.1.1
1996/07/
0
9 06:
22:06
scrappy Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.
2
1996/07/
1
9 06:
08:21
scrappy Exp $
*
*-------------------------------------------------------------------------
*/
...
...
@@ -198,6 +198,24 @@ textout(struct varlena *vlena)
/* ========== PUBLIC ROUTINES ========== */
/*
/*
* textlen -
* returns the actual length of a text* (which may be less than
* the VARSIZE of the text*)
*/
int
textlen
(
text
*
t
)
{
int
i
=
0
;
int
max
=
VARSIZE
(
t
)
-
VARHDRSZ
;
char
*
ptr
=
VARDATA
(
t
);
while
(
i
<
max
&&
*
ptr
++
)
i
++
;
return
i
;
}
/*
* textcat -
* takes two text* and returns a text* that is the concatentation of
...
...
@@ -206,28 +224,21 @@ textout(struct varlena *vlena)
text
*
textcat
(
text
*
t1
,
text
*
t2
)
{
int
newlen
;
char
*
str1
,
*
str2
;
int
len1
,
len2
,
newlen
;
text
*
result
;
if
(
t1
==
NULL
)
return
t2
;
if
(
t2
==
NULL
)
return
t1
;
/* since t1, and t2 are non-null, str1 and str2 must also be non-null */
str1
=
textout
(
t1
);
str2
=
textout
(
t2
);
/* we use strlen here to calculate the length because the size fields
of t1, t2 may be longer than necessary to hold the string */
newlen
=
strlen
(
str1
)
+
strlen
(
str2
)
+
VARHDRSZ
;
result
=
(
text
*
)
palloc
(
newlen
);
strcpy
(
VARDATA
(
result
),
str1
);
strncat
(
VARDATA
(
result
),
str2
,
newlen
-
VARHDRSZ
);
/* [TRH] Was:
strcat(VARDATA(result), str2);
which may corrupt the malloc arena due to writing trailing \0. */
pfree
(
str1
);
pfree
(
str2
);
len1
=
textlen
(
t1
);
len2
=
textlen
(
t2
);
newlen
=
len1
+
len2
+
VARHDRSZ
;
result
=
(
text
*
)
palloc
(
newlen
);
VARSIZE
(
result
)
=
newlen
;
memcpy
(
VARDATA
(
result
),
VARDATA
(
t1
),
len1
);
memcpy
(
VARDATA
(
result
)
+
len1
,
VARDATA
(
t2
),
len2
);
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