libdrgn: vector: fix vector_max_size

(vector_size_type)-1 / sizeof(vector_entry_type) is not a limit;
(vector_size_type)-1 is.

Fixes: b450a7b02b ("libdrgn: vector: support using a smaller type for size/capacity")
Signed-off-by: Omar Sandoval <osandov@osandov.com>
This commit is contained in:
Omar Sandoval 2024-04-05 13:57:40 -07:00
parent 6ae88a0b90
commit 0282abb0e6

View File

@ -367,8 +367,9 @@ static bool vector##_empty(const struct vector *vector) \
} \
\
static const vector##_size_type vector##_max_size = \
min_iconst(PTRDIFF_MAX, (vector##_size_type)-1) \
/ sizeof(vector##_entry_type); \
/* The redundant cast works around llvm/llvm-project#38137. */ \
(vector##_size_type)min_iconst(PTRDIFF_MAX / sizeof(vector##_entry_type),\
(vector##_size_type)-1); \
\
static vector##_size_type vector##_capacity(const struct vector *vector) \
{ \