mirror of
https://github.com/postgres/postgres.git
synced 2025-11-10 17:42:29 +03:00
Fix varatt versus Datum type confusions
Macros like VARDATA() and VARSIZE() should be thought of as taking values of type pointer to struct varlena or some other related struct. The way they are implemented, you can pass anything to it and it will cast it right. But this is in principle incorrect. To fix, add the required DatumGetPointer() calls. Or in a couple of cases, remove superfluous PointerGetDatum() calls. It is planned in a subsequent patch to change macros like VARDATA() and VARSIZE() to inline functions, which will enforce stricter typing. This is in preparation for that. Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us> Discussion: https://www.postgresql.org/message-id/flat/928ea48f-77c6-417b-897c-621ef16685a6%40eisentraut.org
This commit is contained in:
@@ -624,7 +624,7 @@ brin_range_serialize(Ranges *range)
|
||||
|
||||
for (i = 0; i < nvalues; i++)
|
||||
{
|
||||
len += VARSIZE_ANY(range->values[i]);
|
||||
len += VARSIZE_ANY(DatumGetPointer(range->values[i]));
|
||||
}
|
||||
}
|
||||
else if (typlen == -2) /* cstring */
|
||||
|
||||
@@ -189,7 +189,7 @@ getmissingattr(TupleDesc tupleDesc,
|
||||
if (att->attlen > 0)
|
||||
key.len = att->attlen;
|
||||
else
|
||||
key.len = VARSIZE_ANY(attrmiss->am_value);
|
||||
key.len = VARSIZE_ANY(DatumGetPointer(attrmiss->am_value));
|
||||
key.value = attrmiss->am_value;
|
||||
|
||||
entry = hash_search(missing_cache, &key, HASH_ENTER, &found);
|
||||
@@ -901,9 +901,9 @@ expand_tuple(HeapTuple *targetHeapTuple,
|
||||
att->attlen,
|
||||
attrmiss[attnum].am_value);
|
||||
|
||||
targetDataLen = att_addlength_pointer(targetDataLen,
|
||||
att->attlen,
|
||||
attrmiss[attnum].am_value);
|
||||
targetDataLen = att_addlength_datum(targetDataLen,
|
||||
att->attlen,
|
||||
attrmiss[attnum].am_value);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -1190,8 +1190,8 @@ transformRelOptions(Datum oldOptions, List *defList, const char *namspace,
|
||||
|
||||
for (i = 0; i < noldoptions; i++)
|
||||
{
|
||||
char *text_str = VARDATA(oldoptions[i]);
|
||||
int text_len = VARSIZE(oldoptions[i]) - VARHDRSZ;
|
||||
char *text_str = VARDATA(DatumGetPointer(oldoptions[i]));
|
||||
int text_len = VARSIZE(DatumGetPointer(oldoptions[i])) - VARHDRSZ;
|
||||
|
||||
/* Search for a match in defList */
|
||||
foreach(cell, defList)
|
||||
@@ -1456,8 +1456,8 @@ parseRelOptionsInternal(Datum options, bool validate,
|
||||
|
||||
for (i = 0; i < noptions; i++)
|
||||
{
|
||||
char *text_str = VARDATA(optiondatums[i]);
|
||||
int text_len = VARSIZE(optiondatums[i]) - VARHDRSZ;
|
||||
char *text_str = VARDATA(DatumGetPointer(optiondatums[i]));
|
||||
int text_len = VARSIZE(DatumGetPointer(optiondatums[i])) - VARHDRSZ;
|
||||
int j;
|
||||
|
||||
/* Search for a match in reloptions */
|
||||
|
||||
@@ -144,7 +144,7 @@ toast_save_datum(Relation rel, Datum value,
|
||||
int num_indexes;
|
||||
int validIndex;
|
||||
|
||||
Assert(!VARATT_IS_EXTERNAL(value));
|
||||
Assert(!VARATT_IS_EXTERNAL(dval));
|
||||
|
||||
/*
|
||||
* Open the toast relation and its indexes. We can use the index to check
|
||||
|
||||
@@ -2233,7 +2233,7 @@ _gin_build_tuple(OffsetNumber attrnum, unsigned char category,
|
||||
else if (typlen > 0)
|
||||
keylen = typlen;
|
||||
else if (typlen == -1)
|
||||
keylen = VARSIZE_ANY(key);
|
||||
keylen = VARSIZE_ANY(DatumGetPointer(key));
|
||||
else if (typlen == -2)
|
||||
keylen = strlen(DatumGetPointer(key)) + 1;
|
||||
else
|
||||
|
||||
@@ -785,7 +785,7 @@ SpGistGetInnerTypeSize(SpGistTypeDesc *att, Datum datum)
|
||||
else if (att->attlen > 0)
|
||||
size = att->attlen;
|
||||
else
|
||||
size = VARSIZE_ANY(datum);
|
||||
size = VARSIZE_ANY(DatumGetPointer(datum));
|
||||
|
||||
return MAXALIGN(size);
|
||||
}
|
||||
@@ -804,7 +804,7 @@ memcpyInnerDatum(void *target, SpGistTypeDesc *att, Datum datum)
|
||||
}
|
||||
else
|
||||
{
|
||||
size = (att->attlen > 0) ? att->attlen : VARSIZE_ANY(datum);
|
||||
size = (att->attlen > 0) ? att->attlen : VARSIZE_ANY(DatumGetPointer(datum));
|
||||
memcpy(target, DatumGetPointer(datum), size);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -330,7 +330,7 @@ toast_delete_external(Relation rel, const Datum *values, const bool *isnull,
|
||||
|
||||
if (isnull[i])
|
||||
continue;
|
||||
else if (VARATT_IS_EXTERNAL_ONDISK(value))
|
||||
else if (VARATT_IS_EXTERNAL_ONDISK(DatumGetPointer(value)))
|
||||
toast_delete_datum(rel, value, is_speculative);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user