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

Commit8457c69

Browse files
committed
ltree: Zero padding bytes when allocating memory for externally visible data.
ltree/ltree_gist/ltxtquery's headers stores data at MAXALIGN alignment,requiring some padding bytes. So far we left these uninitialized. Zerothose by using palloc0.Author: Andres FreundReported-By: Andres Freund / valgrind / buildarm animal skinkBackpatch: 9.1-
1 parent6041d38 commit8457c69

File tree

5 files changed

+20
-20
lines changed

5 files changed

+20
-20
lines changed

‎contrib/ltree/_ltree_gist.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ _ltree_compress(PG_FUNCTION_ARGS)
8585
(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
8686
errmsg("array must not contain nulls")));
8787

88-
key= (ltree_gist*)palloc(len);
88+
key= (ltree_gist*)palloc0(len);
8989
SET_VARSIZE(key,len);
9090
key->flag=0;
9191

@@ -116,7 +116,7 @@ _ltree_compress(PG_FUNCTION_ARGS)
116116
PG_RETURN_POINTER(retval);
117117
}
118118
len=LTG_HDRSIZE;
119-
key= (ltree_gist*)palloc(len);
119+
key= (ltree_gist*)palloc0(len);
120120
SET_VARSIZE(key,len);
121121
key->flag=LTG_ALLTRUE;
122122

@@ -196,7 +196,7 @@ _ltree_union(PG_FUNCTION_ARGS)
196196
}
197197

198198
len=LTG_HDRSIZE+ ((flag&LTG_ALLTRUE) ?0 :ASIGLEN);
199-
result= (ltree_gist*)palloc(len);
199+
result= (ltree_gist*)palloc0(len);
200200
SET_VARSIZE(result,len);
201201
result->flag=flag;
202202
if (!LTG_ISALLTRUE(result))
@@ -333,26 +333,26 @@ _ltree_picksplit(PG_FUNCTION_ARGS)
333333
/* form initial .. */
334334
if (LTG_ISALLTRUE(GETENTRY(entryvec,seed_1)))
335335
{
336-
datum_l= (ltree_gist*)palloc(LTG_HDRSIZE);
336+
datum_l= (ltree_gist*)palloc0(LTG_HDRSIZE);
337337
SET_VARSIZE(datum_l,LTG_HDRSIZE);
338338
datum_l->flag=LTG_ALLTRUE;
339339
}
340340
else
341341
{
342-
datum_l= (ltree_gist*)palloc(LTG_HDRSIZE+ASIGLEN);
342+
datum_l= (ltree_gist*)palloc0(LTG_HDRSIZE+ASIGLEN);
343343
SET_VARSIZE(datum_l,LTG_HDRSIZE+ASIGLEN);
344344
datum_l->flag=0;
345345
memcpy((void*)LTG_SIGN(datum_l), (void*)LTG_SIGN(GETENTRY(entryvec,seed_1)),sizeof(ABITVEC));
346346
}
347347
if (LTG_ISALLTRUE(GETENTRY(entryvec,seed_2)))
348348
{
349-
datum_r= (ltree_gist*)palloc(LTG_HDRSIZE);
349+
datum_r= (ltree_gist*)palloc0(LTG_HDRSIZE);
350350
SET_VARSIZE(datum_r,LTG_HDRSIZE);
351351
datum_r->flag=LTG_ALLTRUE;
352352
}
353353
else
354354
{
355-
datum_r= (ltree_gist*)palloc(LTG_HDRSIZE+ASIGLEN);
355+
datum_r= (ltree_gist*)palloc0(LTG_HDRSIZE+ASIGLEN);
356356
SET_VARSIZE(datum_r,LTG_HDRSIZE+ASIGLEN);
357357
datum_r->flag=0;
358358
memcpy((void*)LTG_SIGN(datum_r), (void*)LTG_SIGN(GETENTRY(entryvec,seed_2)),sizeof(ABITVEC));

‎contrib/ltree/_ltree_op.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ _ltree_extract_isparent(PG_FUNCTION_ARGS)
211211
PG_RETURN_NULL();
212212
}
213213

214-
item= (ltree*)palloc(VARSIZE(found));
214+
item= (ltree*)palloc0(VARSIZE(found));
215215
memcpy(item,found,VARSIZE(found));
216216

217217
PG_FREE_IF_COPY(la,0);
@@ -234,7 +234,7 @@ _ltree_extract_risparent(PG_FUNCTION_ARGS)
234234
PG_RETURN_NULL();
235235
}
236236

237-
item= (ltree*)palloc(VARSIZE(found));
237+
item= (ltree*)palloc0(VARSIZE(found));
238238
memcpy(item,found,VARSIZE(found));
239239

240240
PG_FREE_IF_COPY(la,0);
@@ -257,7 +257,7 @@ _ltq_extract_regex(PG_FUNCTION_ARGS)
257257
PG_RETURN_NULL();
258258
}
259259

260-
item= (ltree*)palloc(VARSIZE(found));
260+
item= (ltree*)palloc0(VARSIZE(found));
261261
memcpy(item,found,VARSIZE(found));
262262

263263
PG_FREE_IF_COPY(la,0);
@@ -280,7 +280,7 @@ _ltxtq_extract_exec(PG_FUNCTION_ARGS)
280280
PG_RETURN_NULL();
281281
}
282282

283-
item= (ltree*)palloc(VARSIZE(found));
283+
item= (ltree*)palloc0(VARSIZE(found));
284284
memcpy(item,found,VARSIZE(found));
285285

286286
PG_FREE_IF_COPY(la,0);

‎contrib/ltree/ltree_gist.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ ltree_compress(PG_FUNCTION_ARGS)
5656
ltree*val= (ltree*)DatumGetPointer(PG_DETOAST_DATUM(entry->key));
5757
int32len=LTG_HDRSIZE+VARSIZE(val);
5858

59-
key= (ltree_gist*)palloc(len);
59+
key= (ltree_gist*)palloc0(len);
6060
SET_VARSIZE(key,len);
6161
key->flag=LTG_ONENODE;
6262
memcpy((void*)LTG_NODE(key), (void*)val,VARSIZE(val));
@@ -213,7 +213,7 @@ ltree_union(PG_FUNCTION_ARGS)
213213
isleqr= (left==right||ISEQ(left,right)) ? true : false;
214214
*size=LTG_HDRSIZE+ ((isalltrue) ?0 :SIGLEN)+VARSIZE(left)+ ((isleqr) ?0 :VARSIZE(right));
215215

216-
result= (ltree_gist*)palloc(*size);
216+
result= (ltree_gist*)palloc0(*size);
217217
SET_VARSIZE(result,*size);
218218
result->flag=0;
219219

@@ -386,7 +386,7 @@ ltree_picksplit(PG_FUNCTION_ARGS)
386386
lu_l=LTG_GETLNODE(GETENTRY(entryvec,array[FirstOffsetNumber].index));
387387
isleqr= (lu_l==lu_r||ISEQ(lu_l,lu_r)) ? true : false;
388388
size=LTG_HDRSIZE+ ((lisat) ?0 :SIGLEN)+VARSIZE(lu_l)+ ((isleqr) ?0 :VARSIZE(lu_r));
389-
lu= (ltree_gist*)palloc(size);
389+
lu= (ltree_gist*)palloc0(size);
390390
SET_VARSIZE(lu,size);
391391
lu->flag=0;
392392
if (lisat)
@@ -403,7 +403,7 @@ ltree_picksplit(PG_FUNCTION_ARGS)
403403
ru_l=LTG_GETLNODE(GETENTRY(entryvec,array[1+ ((maxoff-FirstOffsetNumber+1) /2)].index));
404404
isleqr= (ru_l==ru_r||ISEQ(ru_l,ru_r)) ? true : false;
405405
size=LTG_HDRSIZE+ ((risat) ?0 :SIGLEN)+VARSIZE(ru_l)+ ((isleqr) ?0 :VARSIZE(ru_r));
406-
ru= (ltree_gist*)palloc(size);
406+
ru= (ltree_gist*)palloc0(size);
407407
SET_VARSIZE(ru,size);
408408
ru->flag=0;
409409
if (risat)
@@ -445,7 +445,7 @@ gist_isparent(ltree_gist *key, ltree *query)
445445
staticltree*
446446
copy_ltree(ltree*src)
447447
{
448-
ltree*dst= (ltree*)palloc(VARSIZE(src));
448+
ltree*dst= (ltree*)palloc0(VARSIZE(src));
449449

450450
memcpy(dst,src,VARSIZE(src));
451451
returndst;

‎contrib/ltree/ltree_op.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ inner_subltree(ltree *t, int32 startpos, int32 endpos)
211211
ptr=LEVEL_NEXT(ptr);
212212
}
213213

214-
res= (ltree*)palloc(LTREE_HDRSIZE+ (end-start));
214+
res= (ltree*)palloc0(LTREE_HDRSIZE+ (end-start));
215215
SET_VARSIZE(res,LTREE_HDRSIZE+ (end-start));
216216
res->numlevel=endpos-startpos;
217217

@@ -268,7 +268,7 @@ ltree_concat(ltree *a, ltree *b)
268268
{
269269
ltree*r;
270270

271-
r= (ltree*)palloc(VARSIZE(a)+VARSIZE(b)-LTREE_HDRSIZE);
271+
r= (ltree*)palloc0(VARSIZE(a)+VARSIZE(b)-LTREE_HDRSIZE);
272272
SET_VARSIZE(r,VARSIZE(a)+VARSIZE(b)-LTREE_HDRSIZE);
273273
r->numlevel=a->numlevel+b->numlevel;
274274

@@ -450,7 +450,7 @@ lca_inner(ltree **a, int len)
450450
l1=LEVEL_NEXT(l1);
451451
}
452452

453-
res= (ltree*)palloc(reslen);
453+
res= (ltree*)palloc0(reslen);
454454
SET_VARSIZE(res,reslen);
455455
res->numlevel=num;
456456

‎contrib/ltree/ltxtquery_io.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ queryin(char *buf)
350350
errmsg("ltxtquery is too large")));
351351
commonlen=COMPUTESIZE(state.num,state.sumlen);
352352

353-
query= (ltxtquery*)palloc(commonlen);
353+
query= (ltxtquery*)palloc0(commonlen);
354354
SET_VARSIZE(query,commonlen);
355355
query->size=state.num;
356356
ptr=GETQUERY(query);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp