From 0282abb0e6bb9cdd8b3884df4c919701ab4c3193 Mon Sep 17 00:00:00 2001 From: Omar Sandoval Date: Fri, 5 Apr 2024 13:57:40 -0700 Subject: [PATCH] libdrgn: vector: fix vector_max_size (vector_size_type)-1 / sizeof(vector_entry_type) is not a limit; (vector_size_type)-1 is. Fixes: b450a7b02b34 ("libdrgn: vector: support using a smaller type for size/capacity") Signed-off-by: Omar Sandoval --- libdrgn/vector.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libdrgn/vector.h b/libdrgn/vector.h index 5da4fa55..8467cf63 100644 --- a/libdrgn/vector.h +++ b/libdrgn/vector.h @@ -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) \ { \