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

Commite54c230

Browse files
committed
Use palloc0 in making key to get rid of valgrind errors
1 parente9928b8 commite54c230

File tree

1 file changed

+46
-43
lines changed

1 file changed

+46
-43
lines changed

‎jsonb_gin_ops.c

Lines changed: 46 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -258,51 +258,54 @@ make_gin_key(JsonbValue *v, uint32 hash)
258258
{
259259
GINKey*key;
260260

261-
if (v->type==jbvNull)
261+
switch (v->type)
262262
{
263-
key= (GINKey*)palloc(GINKEYLEN);
264-
key->type=v->type;
265-
SET_VARSIZE(key,GINKEYLEN);
266-
}
267-
elseif (v->type==jbvBool)
268-
{
269-
key= (GINKey*)palloc(GINKEYLEN);
270-
key->type=v->type | (v->val.boolean ?GINKeyTrue :0);
271-
SET_VARSIZE(key,GINKEYLEN);
272-
}
273-
elseif (v->type==jbvArray)
274-
{
275-
key= (GINKey*)palloc(GINKEYLEN);
276-
key->type=v->type;
277-
if (v->val.array.nElems==0)
278-
key->type |=GINKeyEmptyArray;
279-
SET_VARSIZE(key,GINKEYLEN);
280-
}
281-
elseif (v->type==jbvObject)
282-
{
283-
key= (GINKey*)palloc(GINKEYLEN);
284-
key->type=v->type;
285-
SET_VARSIZE(key,GINKEYLEN);
286-
}
287-
elseif (v->type==jbvNumeric)
288-
{
289-
key= (GINKey*)palloc(GINKeyLenNumeric(VARSIZE_ANY(v->val.numeric)));
290-
key->type=v->type;
291-
memcpy(GINKeyDataNumeric(key),v->val.numeric,VARSIZE_ANY(v->val.numeric));
292-
SET_VARSIZE(key,GINKeyLenNumeric(VARSIZE_ANY(v->val.numeric)));
293-
}
294-
elseif (v->type==jbvString)
295-
{
296-
key= (GINKey*)palloc(GINKeyLenString);
297-
key->type=v->type;
298-
GINKeyDataString(key)=hash_any((unsignedchar*)v->val.string.val,
299-
v->val.string.len);
300-
SET_VARSIZE(key,GINKeyLenString);
301-
}
302-
else
303-
{
304-
elog(ERROR,"GINKey must be scalar");
263+
casejbvNull:
264+
casejbvObject:
265+
{
266+
key= (GINKey*)palloc(GINKEYLEN);
267+
key->type=v->type;
268+
SET_VARSIZE(key,GINKEYLEN);
269+
break;
270+
}
271+
casejbvBool:
272+
{
273+
key= (GINKey*)palloc(GINKEYLEN);
274+
key->type=v->type | (v->val.boolean ?GINKeyTrue :0);
275+
SET_VARSIZE(key,GINKEYLEN);
276+
break;
277+
}
278+
casejbvArray:
279+
{
280+
key= (GINKey*)palloc(GINKEYLEN);
281+
key->type=v->type;
282+
if (v->val.array.nElems==0)
283+
key->type |=GINKeyEmptyArray;
284+
285+
SET_VARSIZE(key,GINKEYLEN);
286+
break;
287+
}
288+
casejbvNumeric:
289+
{
290+
key= (GINKey*)palloc0(GINKeyLenNumeric(VARSIZE_ANY(v->val.numeric)));
291+
key->type=v->type;
292+
memcpy(GINKeyDataNumeric(key),v->val.numeric,VARSIZE_ANY(v->val.numeric));
293+
SET_VARSIZE(key,GINKeyLenNumeric(VARSIZE_ANY(v->val.numeric)));
294+
break;
295+
}
296+
casejbvString:
297+
{
298+
key= (GINKey*)palloc0(GINKeyLenString);
299+
key->type=v->type;
300+
GINKeyDataString(key)=hash_any((unsignedchar*)v->val.string.val,
301+
v->val.string.len);
302+
SET_VARSIZE(key,GINKeyLenString);
303+
break;
304+
}
305+
default:
306+
elog(ERROR,"GINKey must be scalar");
305307
}
308+
306309
key->hash=hash;
307310
returnkey;
308311
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp