Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit64bfa04

Browse files
committed
fixes for textcat(), but headers were missing from archive :(
1 parent89ad633 commit64bfa04

File tree

1 file changed

+29
-18
lines changed

1 file changed

+29
-18
lines changed

‎src/backend/utils/adt/varlena.c

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.1.1.1 1996/07/09 06:22:06 scrappy Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.2 1996/07/19 06:08:21 scrappy Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -198,6 +198,24 @@ textout(struct varlena *vlena)
198198

199199
/* ========== PUBLIC ROUTINES ========== */
200200

201+
/*
202+
203+
/*
204+
* textlen -
205+
* returns the actual length of a text* (which may be less than
206+
* the VARSIZE of the text*)
207+
*/
208+
209+
inttextlen (text*t)
210+
{
211+
inti=0;
212+
intmax=VARSIZE(t)-VARHDRSZ;
213+
char*ptr=VARDATA(t);
214+
while (i<max&&*ptr++)
215+
i++;
216+
returni;
217+
}
218+
201219
/*
202220
* textcat -
203221
* takes two text* and returns a text* that is the concatentation of
@@ -206,28 +224,21 @@ textout(struct varlena *vlena)
206224
text*
207225
textcat(text*t1,text*t2)
208226
{
209-
intnewlen;
210-
char*str1,*str2;
227+
intlen1,len2,newlen;
211228
text*result;
212229

213230
if (t1==NULL)returnt2;
214231
if (t2==NULL)returnt1;
215232

216-
/* since t1, and t2 are non-null, str1 and str2 must also be non-null */
217-
str1=textout(t1);
218-
str2=textout(t2);
219-
/* we use strlen here to calculate the length because the size fields
220-
of t1, t2 may be longer than necessary to hold the string */
221-
newlen=strlen(str1)+strlen(str2)+VARHDRSZ;
222-
result= (text*)palloc(newlen);
223-
strcpy(VARDATA(result),str1);
224-
strncat(VARDATA(result),str2,newlen-VARHDRSZ);
225-
/* [TRH] Was:
226-
strcat(VARDATA(result), str2);
227-
which may corrupt the malloc arena due to writing trailing \0. */
228-
229-
pfree(str1);
230-
pfree(str2);
233+
len1=textlen (t1);
234+
len2=textlen (t2);
235+
newlen=len1+len2+VARHDRSZ;
236+
result= (text*)palloc (newlen);
237+
238+
VARSIZE(result)=newlen;
239+
memcpy (VARDATA(result),VARDATA(t1),len1);
240+
memcpy (VARDATA(result)+len1,VARDATA(t2),len2);
241+
231242
returnresult;
232243
}
233244

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp