mirror of
https://github.com/timescale/timescaledb.git
synced 2025-05-16 02:23:49 +08:00
Add assert for fetch_att and store_att_byval
These two functions throw an error if you pass in a strange combination of typbyval and typlen, so we assert on bad values to get a backtrace.
This commit is contained in:
parent
3834d81b46
commit
f754918e89
10
src/utils.h
10
src/utils.h
@ -188,6 +188,16 @@ extern TSDLLEXPORT List *ts_get_reloptions(Oid relid);
|
||||
.value = 0, .isnull = true \
|
||||
}
|
||||
|
||||
static inline Datum
|
||||
ts_fetch_att(const void *T, bool attbyval, int attlen)
|
||||
{
|
||||
/* Length should be set to something sensible, otherwise an error will be
|
||||
* raised by fetch_att, so we assert this here to get a stack for
|
||||
* violations. */
|
||||
Assert(!attbyval || (attlen > 0 && attlen <= 8));
|
||||
return fetch_att(T, attbyval, attlen);
|
||||
}
|
||||
|
||||
static inline int64
|
||||
int64_min(int64 a, int64 b)
|
||||
{
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
#include <compat/compat.h>
|
||||
#include "datum_serialize.h"
|
||||
#include "src/utils.h"
|
||||
#include <compression/compression.h>
|
||||
|
||||
typedef struct DatumSerializer
|
||||
@ -167,6 +168,11 @@ datum_to_bytes_and_advance(DatumSerializer *serializer, char *start, Size *max_s
|
||||
start = align_and_zero(start, serializer->type_align, max_size);
|
||||
data_length = serializer->type_len;
|
||||
check_allowed_data_len(data_length, *max_size);
|
||||
|
||||
/* Data length should be set to something sensible, otherwise an error
|
||||
* will be raised inside store_att_byval, so we assert here to get a
|
||||
* stack. */
|
||||
Assert(data_length > 0 && data_length <= 8);
|
||||
store_att_byval(start, datum, data_length);
|
||||
}
|
||||
else if (serializer->type_len == -1)
|
||||
@ -322,7 +328,7 @@ bytes_to_datum_and_advance(DatumDeserializer *deserializer, const char **ptr)
|
||||
CheckCompressedData((VARATT_IS_1B(*ptr) && VARSIZE_1B(*ptr) >= VARHDRSZ_SHORT) ||
|
||||
(VARSIZE_4B(*ptr) > VARHDRSZ));
|
||||
}
|
||||
res = fetch_att(*ptr, deserializer->type_by_val, deserializer->type_len);
|
||||
res = ts_fetch_att(*ptr, deserializer->type_by_val, deserializer->type_len);
|
||||
*ptr = att_addlength_pointer(*ptr, deserializer->type_len, *ptr);
|
||||
return res;
|
||||
}
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include "arrow_array.h"
|
||||
#include "compression/arrow_c_data_interface.h"
|
||||
#include "compression/compression.h"
|
||||
#include "src/utils.h"
|
||||
|
||||
#define TYPLEN_VARLEN (-1)
|
||||
|
||||
@ -470,7 +471,7 @@ arrow_get_datum_fixlen(const ArrowArray *array, Oid typid, int16 typlen, uint16
|
||||
/* In order to handle fixed-length values of arbitrary size that are byref
|
||||
* and byval, we use fetch_all() rather than rolling our own. This is
|
||||
* taken from utils/adt/rangetypes.c */
|
||||
Datum datum = fetch_att(&values[index * typlen], apriv->typbyval, typlen);
|
||||
Datum datum = ts_fetch_att(&values[index * typlen], apriv->typbyval, typlen);
|
||||
|
||||
TS_DEBUG_LOG("retrieved fixlen value %s row %u from offset %u"
|
||||
" in memory context %s",
|
||||
|
@ -7,10 +7,9 @@
|
||||
#include <postgres.h>
|
||||
|
||||
#include "compression/arrow_c_data_interface.h"
|
||||
|
||||
#include "vector_predicates.h"
|
||||
|
||||
#include "compression/compression.h"
|
||||
#include "src/utils.h"
|
||||
#include "vector_predicates.h"
|
||||
|
||||
/*
|
||||
* Vectorized implementation of ScalarArrayOpExpr. Applies scalar_predicate for
|
||||
@ -77,7 +76,7 @@ vector_array_predicate(VectorPredicate *vector_const_predicate, bool is_or,
|
||||
}
|
||||
return;
|
||||
}
|
||||
Datum constvalue = fetch_att(array_data, typbyval, typlen);
|
||||
Datum constvalue = ts_fetch_att(array_data, typbyval, typlen);
|
||||
array_data = att_addlength_pointer(array_data, typlen, array_data);
|
||||
array_data = (const char *) att_align_nominal(array_data, typalign);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user