From c555e40dd7cdf29ccd6c7f14056880303372a893 Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Fri, 14 Aug 2026 08:29:23 -0700 Subject: [PATCH v1] Fix conversion warnings in headers --- src/include/access/htup_details.h | 2 +- src/include/access/tableam.h | 2 +- src/include/access/tupdesc.h | 2 +- src/include/access/tupmacs.h | 10 +++++----- src/include/catalog/index.h | 2 +- src/include/lib/simplehash.h | 16 ++++++++-------- src/include/libpq/pqformat.h | 4 ++-- src/include/mb/pg_wchar.h | 4 ++-- src/include/nodes/pg_list.h | 2 +- src/include/port/atomics/generic-gcc.h | 8 ++++---- src/include/port/atomics/generic.h | 8 ++++---- src/include/port/pg_bitutils.h | 4 ++-- src/include/storage/bufpage.h | 4 ++-- src/include/utils/array.h | 6 +++--- src/include/utils/relptr.h | 2 +- src/include/varatt.h | 6 +++--- 16 files changed, 41 insertions(+), 41 deletions(-) diff --git a/src/include/access/htup_details.h b/src/include/access/htup_details.h index 77a6c48fd71..c43931cc6f2 100644 --- a/src/include/access/htup_details.h +++ b/src/include/access/htup_details.h @@ -482,7 +482,7 @@ HeapTupleHeaderSetMovedPartitions(HeapTupleHeaderData *tup) static inline uint32 HeapTupleHeaderGetDatumLength(const HeapTupleHeaderData *tup) { - return VARSIZE(tup); + return (uint32) VARSIZE(tup); } static inline void diff --git a/src/include/access/tableam.h b/src/include/access/tableam.h index ff03a2b816f..770e37c9b72 100644 --- a/src/include/access/tableam.h +++ b/src/include/access/tableam.h @@ -919,7 +919,7 @@ table_beginscan_common(Relation rel, Snapshot snapshot, int nkeys, uint32 flags, uint32 user_flags) { Assert((user_flags & SO_INTERNAL_FLAGS) == 0); - Assert((flags & ~SO_INTERNAL_FLAGS) == 0); + Assert((flags & (uint32) ~SO_INTERNAL_FLAGS) == 0); flags |= user_flags; /* diff --git a/src/include/access/tupdesc.h b/src/include/access/tupdesc.h index d26287271e9..6b4eb23a02f 100644 --- a/src/include/access/tupdesc.h +++ b/src/include/access/tupdesc.h @@ -171,7 +171,7 @@ extern void populate_compact_attribute(TupleDesc tupdesc, int attnum); #define TupleDescAttrAddress(desc) \ (Form_pg_attribute) ((char *) (desc) + \ (offsetof(struct TupleDescData, compact_attrs) + \ - (desc)->natts * sizeof(CompactAttribute))) + (Size) (desc)->natts * sizeof(CompactAttribute))) /* Accessor for the i'th FormData_pg_attribute element of tupdesc. */ static inline FormData_pg_attribute * diff --git a/src/include/access/tupmacs.h b/src/include/access/tupmacs.h index fa76d0f2eac..b9d8654dd64 100644 --- a/src/include/access/tupmacs.h +++ b/src/include/access/tupmacs.h @@ -60,7 +60,7 @@ populate_isnull_array(const uint8 *bits, int natts, bool *isnull) for (int i = 0; i < nbytes; i++, isnull += 8) { uint64 isnull_8; - uint8 nullbyte = ~bits[i]; + uint8 nullbyte = (uint8) ~bits[i]; /* Convert the lower 4 bits of NULL bitmap word into a 64 bit int */ isnull_8 = (nullbyte & 0xf) * SPREAD_BITS_MULTIPLIER_32; @@ -178,9 +178,9 @@ align_fetch_then_add(const char *tupptr, uint32 *off, bool attbyval, int attlen, { const char *offset_ptr; - *off = TYPEALIGN(attalignby, *off); + *off = (uint32) TYPEALIGN(attalignby, *off); offset_ptr = tupptr + *off; - *off += attlen; + *off += (uint32) attlen; if (attbyval) { switch (attlen) @@ -206,7 +206,7 @@ align_fetch_then_add(const char *tupptr, uint32 *off, bool attbyval, int attlen, else if (attlen == -1) { if (!VARATT_IS_SHORT(tupptr + *off)) - *off = TYPEALIGN(attalignby, *off); + *off = (uint32) TYPEALIGN(attalignby, *off); res = PointerGetDatum(tupptr + *off); *off += VARSIZE_ANY(DatumGetPointer(res)); @@ -215,7 +215,7 @@ align_fetch_then_add(const char *tupptr, uint32 *off, bool attbyval, int attlen, else { Assert(attlen == -2); - *off = TYPEALIGN(attalignby, *off); + *off = (uint32) TYPEALIGN(attalignby, *off); res = PointerGetDatum(tupptr + *off); *off += strlen(tupptr + *off) + 1; return res; diff --git a/src/include/catalog/index.h b/src/include/catalog/index.h index b952ad071d3..bc75dc10af6 100644 --- a/src/include/catalog/index.h +++ b/src/include/catalog/index.h @@ -207,7 +207,7 @@ itemptr_encode(const ItemPointerData *itemptr) * cannot be negative encoded values (We assume a two's complement * representation). */ - encoded = ((uint64) block << 16) | (uint16) offset; + encoded = (int64) (((uint64) block << 16) | (uint16) offset); return encoded; } diff --git a/src/include/lib/simplehash.h b/src/include/lib/simplehash.h index 15af488abfb..dac684d464f 100644 --- a/src/include/lib/simplehash.h +++ b/src/include/lib/simplehash.h @@ -352,9 +352,9 @@ SH_UPDATE_PARAMETERS(SH_TYPE * tb, uint64 newsize) * again. */ if (tb->size == SH_MAX_SIZE) - tb->grow_threshold = ((double) tb->size) * SH_MAX_FILLFACTOR; + tb->grow_threshold = (uint32) (((double) tb->size) * SH_MAX_FILLFACTOR); else - tb->grow_threshold = ((double) tb->size) * SH_FILLFACTOR; + tb->grow_threshold = (uint32) (((double) tb->size) * SH_FILLFACTOR); } /* return the optimal bucket for the hash */ @@ -393,7 +393,7 @@ SH_DISTANCE_FROM_OPTIMAL(SH_TYPE * tb, uint32 optimal, uint32 bucket) if (optimal <= bucket) return bucket - optimal; else - return (tb->size + bucket) - optimal; + return (uint32) ((tb->size + bucket) - optimal); } static inline uint32 @@ -462,7 +462,7 @@ SH_CREATE(MemoryContext ctx, uint32 nelements, void *private_data) tb->private_data = private_data; /* increase nelements by fillfactor, want to store nelements elements */ - size = Min((double) SH_MAX_SIZE, ((double) nelements) / SH_FILLFACTOR); + size = (uint64) Min((double) SH_MAX_SIZE, ((double) nelements) / SH_FILLFACTOR); size = SH_COMPUTE_SIZE(size); @@ -716,7 +716,7 @@ restart: * explosion for some weird edge cases. */ if (unlikely(++emptydist > SH_GROW_MAX_MOVE) && - ((double) tb->members / tb->size) >= SH_GROW_MIN_FILLFACTOR) + ((double) tb->members / (double) tb->size) >= SH_GROW_MIN_FILLFACTOR) { tb->grow_threshold = 0; goto restart; @@ -766,7 +766,7 @@ restart: * explosion for some weird edge cases. */ if (unlikely(insertdist > SH_GROW_MAX_DIB) && - ((double) tb->members / tb->size) >= SH_GROW_MIN_FILLFACTOR) + ((double) tb->members / (double) tb->size) >= SH_GROW_MIN_FILLFACTOR) { tb->grow_threshold = 0; goto restart; @@ -938,7 +938,7 @@ SH_DELETE_ITEM(SH_TYPE * tb, SH_ELEMENT_TYPE * entry) uint32 curelem; /* Calculate the index of 'entry' */ - curelem = entry - &tb->data[0]; + curelem = (uint32) (entry - &tb->data[0]); tb->members--; @@ -1012,7 +1012,7 @@ SH_START_ITERATE(SH_TYPE * tb, SH_ITERATOR * iter) * Iterate backwards, that allows the current element to be deleted, even * if there are backward shifts */ - iter->cur = startelem; + iter->cur = (uint32) startelem; iter->end = iter->cur; iter->done = false; } diff --git a/src/include/libpq/pqformat.h b/src/include/libpq/pqformat.h index bc4ab1381a9..60a0a9f169d 100644 --- a/src/include/libpq/pqformat.h +++ b/src/include/libpq/pqformat.h @@ -107,12 +107,12 @@ pq_writeint64(StringInfoData *pg_restrict buf, uint64 i) static inline void pq_writestring(StringInfoData *pg_restrict buf, const char *pg_restrict str) { - int slen = strlen(str); + int slen = (int) strlen(str); char *p; p = pg_server_to_client(str, slen); if (p != str) /* actual conversion has been done? */ - slen = strlen(p); + slen = (int) strlen(p); Assert(buf->len + slen + 1 <= buf->maxlen); diff --git a/src/include/mb/pg_wchar.h b/src/include/mb/pg_wchar.h index deee2a832c3..4b0b31dc276 100644 --- a/src/include/mb/pg_wchar.h +++ b/src/include/mb/pg_wchar.h @@ -389,7 +389,7 @@ is_utf16_surrogate_second(char32_t c) static inline char32_t surrogate_pair_to_codepoint(char16_t first, char16_t second) { - return ((first & 0x3FF) << 10) + 0x10000 + (second & 0x3FF); + return (char32_t) (((first & 0x3FF) << 10) + 0x10000 + (second & 0x3FF)); } /* @@ -429,7 +429,7 @@ unicode_to_utf8(char32_t c, unsigned char *utf8string) { if (c <= 0x7F) { - utf8string[0] = c; + utf8string[0] = (unsigned char) c; } else if (c <= 0x7FF) { diff --git a/src/include/nodes/pg_list.h b/src/include/nodes/pg_list.h index e93bcbf2698..72db8b85fc1 100644 --- a/src/include/nodes/pg_list.h +++ b/src/include/nodes/pg_list.h @@ -365,7 +365,7 @@ static inline int list_cell_number(const List *l, const ListCell *c) { Assert(c >= &l->elements[0] && c < &l->elements[l->length]); - return c - l->elements; + return (int) (c - l->elements); } /* diff --git a/src/include/port/atomics/generic-gcc.h b/src/include/port/atomics/generic-gcc.h index 5bfce82f687..a55199683fa 100644 --- a/src/include/port/atomics/generic-gcc.h +++ b/src/include/port/atomics/generic-gcc.h @@ -205,7 +205,7 @@ pg_atomic_exchange_u32_impl(volatile pg_atomic_uint32 *ptr, uint32 newval) static inline uint32 pg_atomic_fetch_add_u32_impl(volatile pg_atomic_uint32 *ptr, int32 add_) { - return __sync_fetch_and_add(&ptr->value, add_); + return __sync_fetch_and_add(&ptr->value, (uint32) add_); } #endif @@ -214,7 +214,7 @@ pg_atomic_fetch_add_u32_impl(volatile pg_atomic_uint32 *ptr, int32 add_) static inline uint32 pg_atomic_fetch_sub_u32_impl(volatile pg_atomic_uint32 *ptr, int32 sub_) { - return __sync_fetch_and_sub(&ptr->value, sub_); + return __sync_fetch_and_sub(&ptr->value, (uint32) sub_); } #endif @@ -292,7 +292,7 @@ pg_atomic_exchange_u64_impl(volatile pg_atomic_uint64 *ptr, uint64 newval) static inline uint64 pg_atomic_fetch_add_u64_impl(volatile pg_atomic_uint64 *ptr, int64 add_) { - return __sync_fetch_and_add(&ptr->value, add_); + return __sync_fetch_and_add(&ptr->value, (uint64) add_); } #endif @@ -301,7 +301,7 @@ pg_atomic_fetch_add_u64_impl(volatile pg_atomic_uint64 *ptr, int64 add_) static inline uint64 pg_atomic_fetch_sub_u64_impl(volatile pg_atomic_uint64 *ptr, int64 sub_) { - return __sync_fetch_and_sub(&ptr->value, sub_); + return __sync_fetch_and_sub(&ptr->value, (uint64) sub_); } #endif diff --git a/src/include/port/atomics/generic.h b/src/include/port/atomics/generic.h index daa772e9a6d..ea1d6928344 100644 --- a/src/include/port/atomics/generic.h +++ b/src/include/port/atomics/generic.h @@ -214,7 +214,7 @@ pg_atomic_fetch_or_u32_impl(volatile pg_atomic_uint32 *ptr, uint32 or_) static inline uint32 pg_atomic_add_fetch_u32_impl(volatile pg_atomic_uint32 *ptr, int32 add_) { - return pg_atomic_fetch_add_u32_impl(ptr, add_) + add_; + return pg_atomic_fetch_add_u32_impl(ptr, add_) + (uint32) add_; } #endif @@ -223,7 +223,7 @@ pg_atomic_add_fetch_u32_impl(volatile pg_atomic_uint32 *ptr, int32 add_) static inline uint32 pg_atomic_sub_fetch_u32_impl(volatile pg_atomic_uint32 *ptr, int32 sub_) { - return pg_atomic_fetch_sub_u32_impl(ptr, sub_) - sub_; + return pg_atomic_fetch_sub_u32_impl(ptr, sub_) - (uint32) sub_; } #endif @@ -398,7 +398,7 @@ pg_atomic_fetch_or_u64_impl(volatile pg_atomic_uint64 *ptr, uint64 or_) static inline uint64 pg_atomic_add_fetch_u64_impl(volatile pg_atomic_uint64 *ptr, int64 add_) { - return pg_atomic_fetch_add_u64_impl(ptr, add_) + add_; + return pg_atomic_fetch_add_u64_impl(ptr, add_) + (uint64) add_; } #endif @@ -407,7 +407,7 @@ pg_atomic_add_fetch_u64_impl(volatile pg_atomic_uint64 *ptr, int64 add_) static inline uint64 pg_atomic_sub_fetch_u64_impl(volatile pg_atomic_uint64 *ptr, int64 sub_) { - return pg_atomic_fetch_sub_u64_impl(ptr, sub_) - sub_; + return pg_atomic_fetch_sub_u64_impl(ptr, sub_) - (uint64) sub_; } #endif diff --git a/src/include/port/pg_bitutils.h b/src/include/port/pg_bitutils.h index 2864ba431db..b9275e9e5ad 100644 --- a/src/include/port/pg_bitutils.h +++ b/src/include/port/pg_bitutils.h @@ -260,7 +260,7 @@ pg_ceil_log2_32(uint32 num) if (num < 2) return 0; else - return pg_leftmost_one_pos32(num - 1) + 1; + return (uint32) (pg_leftmost_one_pos32(num - 1) + 1); } /* @@ -273,7 +273,7 @@ pg_ceil_log2_64(uint64 num) if (num < 2) return 0; else - return pg_leftmost_one_pos64(num - 1) + 1; + return (uint64) (pg_leftmost_one_pos64(num - 1) + 1); } extern uint64 pg_popcount_portable(const char *buf, int bytes); diff --git a/src/include/storage/bufpage.h b/src/include/storage/bufpage.h index 634e1e49ee5..83e252474d8 100644 --- a/src/include/storage/bufpage.h +++ b/src/include/storage/bufpage.h @@ -327,7 +327,7 @@ PageSetPageSizeAndVersion(Page page, Size size, uint8 version) Assert((size & 0xFF00) == size); Assert((version & 0x00FF) == version); - ((PageHeader) page)->pd_pagesize_version = size | version; + ((PageHeader) page)->pd_pagesize_version = (uint16) (size | version); } /* ---------------- @@ -341,7 +341,7 @@ PageSetPageSizeAndVersion(Page page, Size size, uint8 version) static inline uint16 PageGetSpecialSize(const PageData *page) { - return (PageGetPageSize(page) - ((const PageHeaderData *) page)->pd_special); + return (uint16) (PageGetPageSize(page) - ((const PageHeaderData *) page)->pd_special); } /* diff --git a/src/include/utils/array.h b/src/include/utils/array.h index 88e4f4d70d8..a59a4e87926 100644 --- a/src/include/utils/array.h +++ b/src/include/utils/array.h @@ -308,13 +308,13 @@ typedef struct ArrayIteratorData *ArrayIterator; * number of dimensions and total number of items. */ #define ARR_OVERHEAD_NONULLS(ndims) \ - MAXALIGN(sizeof(ArrayType) + 2 * sizeof(int) * (ndims)) + MAXALIGN(sizeof(ArrayType) + 2 * sizeof(int) * (Size) (ndims)) #define ARR_OVERHEAD_WITHNULLS(ndims, nitems) \ - MAXALIGN(sizeof(ArrayType) + 2 * sizeof(int) * (ndims) + \ + MAXALIGN(sizeof(ArrayType) + 2 * sizeof(int) * (Size) (ndims) + \ ((nitems) + 7) / 8) #define ARR_DATA_OFFSET(a) \ - (ARR_HASNULL(a) ? (a)->dataoffset : ARR_OVERHEAD_NONULLS(ARR_NDIM(a))) + (ARR_HASNULL(a) ? (Size) (a)->dataoffset : ARR_OVERHEAD_NONULLS(ARR_NDIM(a))) /* * Returns a pointer to the actual array data. diff --git a/src/include/utils/relptr.h b/src/include/utils/relptr.h index 94975f2f237..0838dd650b6 100644 --- a/src/include/utils/relptr.h +++ b/src/include/utils/relptr.h @@ -64,7 +64,7 @@ relptr_store_eval(char *base, char *val) else { Assert(val >= base); - return val - base + 1; + return (Size) (val - base + 1); } } diff --git a/src/include/varatt.h b/src/include/varatt.h index 000bdf33b92..de63feedaf9 100644 --- a/src/include/varatt.h +++ b/src/include/varatt.h @@ -94,7 +94,7 @@ typedef enum vartag_external static inline bool VARTAG_IS_EXPANDED(vartag_external tag) { - return ((tag & ~1) == VARTAG_EXPANDED_RO); + return ((tag & (unsigned int) ~1) == VARTAG_EXPANDED_RO); } /* Size of the data part of a "TOAST pointer" datum */ @@ -251,10 +251,10 @@ typedef struct #define SET_VARSIZE_4B_C(PTR,len) \ (((varattrib_4b *) (PTR))->va_4byte.va_header = (((uint32) (len)) << 2) | 0x02) #define SET_VARSIZE_1B(PTR,len) \ - (((varattrib_1b *) (PTR))->va_header = (((uint8) (len)) << 1) | 0x01) + (((varattrib_1b *) (PTR))->va_header = (uint8) ((((uint8) (len)) << 1) | 0x01)) #define SET_VARTAG_1B_E(PTR,tag) \ (((varattrib_1b_e *) (PTR))->va_header = 0x01, \ - ((varattrib_1b_e *) (PTR))->va_tag = (tag)) + ((varattrib_1b_e *) (PTR))->va_tag = (uint8) (tag)) #endif /* WORDS_BIGENDIAN */ -- 2.52.0