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

Appearance settings

Commit e54c230

Browse filesBrowse files
committed
Use palloc0 in making key to get rid of valgrind errors
1 parent e9928b8 commit e54c230
Copy full SHA for e54c230

File tree

1 file changed

+46
-43
lines changed
Filter options

1 file changed

+46
-43
lines changed

‎jsonb_gin_ops.c

Copy file name to clipboardExpand all lines: jsonb_gin_ops.c
+46-43Lines 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-
else if (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-
else if (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-
else if (v->type == jbvObject)
282-
{
283-
key = (GINKey *)palloc(GINKEYLEN);
284-
key->type = v->type;
285-
SET_VARSIZE(key, GINKEYLEN);
286-
}
287-
else if (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-
else if (v->type == jbvString)
295-
{
296-
key = (GINKey *)palloc(GINKeyLenString);
297-
key->type = v->type;
298-
GINKeyDataString(key) = hash_any((unsigned char *)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+
case jbvNull:
264+
case jbvObject:
265+
{
266+
key = (GINKey *)palloc(GINKEYLEN);
267+
key->type = v->type;
268+
SET_VARSIZE(key, GINKEYLEN);
269+
break;
270+
}
271+
case jbvBool:
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+
case jbvArray:
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+
case jbvNumeric:
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+
case jbvString:
297+
{
298+
key = (GINKey *) palloc0(GINKeyLenString);
299+
key->type = v->type;
300+
GINKeyDataString(key) = hash_any((unsigned char *)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
return key;
308311
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.