Fix accidentally cast away qualifiers
authorPeter Eisentraut <peter@eisentraut.org>
Mon, 26 Jan 2026 15:02:31 +0000 (16:02 +0100)
committerPeter Eisentraut <peter@eisentraut.org>
Mon, 26 Jan 2026 15:02:31 +0000 (16:02 +0100)
This fixes cases where a qualifier (const, in all cases here) was
dropped by a cast, but the cast was otherwise necessary or desirable,
so the straightforward fix is to add the qualifier into the cast.

Co-authored-by: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/b04f4d3a-5e70-4e73-9ef2-87f777ca4aac%40eisentraut.org

42 files changed:
contrib/intarray/_int_selfuncs.c
contrib/pageinspect/heapfuncs.c
contrib/uuid-ossp/uuid-ossp.c
src/backend/access/common/toast_compression.c
src/backend/access/nbtree/nbtinsert.c
src/backend/access/spgist/spgquadtreeproc.c
src/backend/access/transam/xloginsert.c
src/backend/backup/backup_manifest.c
src/backend/backup/basebackup.c
src/backend/backup/basebackup_incremental.c
src/backend/executor/nodeIndexscan.c
src/backend/libpq/auth-scram.c
src/backend/libpq/crypt.c
src/backend/nodes/nodeFuncs.c
src/backend/nodes/outfuncs.c
src/backend/nodes/tidbitmap.c
src/backend/statistics/extended_stats.c
src/backend/storage/ipc/shm_mq.c
src/backend/tsearch/spell.c
src/backend/utils/adt/geo_spgist.c
src/backend/utils/adt/json.c
src/backend/utils/adt/pg_locale_builtin.c
src/backend/utils/adt/rangetypes.c
src/backend/utils/adt/rangetypes_gist.c
src/bin/pg_basebackup/walmethods.c
src/bin/pg_rewind/filemap.c
src/bin/pg_verifybackup/astreamer_verify.c
src/bin/pg_walsummary/pg_walsummary.c
src/common/scram-common.c
src/common/unicode/case_test.c
src/common/unicode_case.c
src/include/access/tupmacs.h
src/include/common/hashfn_unstable.h
src/include/utils/memutils.h
src/include/varatt.h
src/interfaces/libpq/fe-auth-scram.c
src/interfaces/libpq/fe-auth.c
src/port/pg_crc32c_armv8.c
src/port/pg_popcount_aarch64.c
src/test/isolation/isolationtester.c
src/test/modules/libpq_pipeline/libpq_pipeline.c
src/test/modules/test_tidstore/test_tidstore.c

index c3e19cdf27f2b7f7eabf4af9cc35ad474ce7d32d..4a7053028c6249958aa7733e60cb644834a799ba 100644 (file)
@@ -328,7 +328,7 @@ int_query_opr_selec(ITEM *item, Datum *mcelems, float4 *mcefreqs,
 static int
 compare_val_int4(const void *a, const void *b)
 {
-   int32       key = *(int32 *) a;
+   int32       key = *(const int32 *) a;
    int32       value = DatumGetInt32(*(const Datum *) b);
 
    if (key < value)
index 1cf0b44e731c0a80be68c5b380bcc1f81a4b1c4e..8277fa256c371c1e4f5dbe56db5054391dfd224a 100644 (file)
@@ -46,7 +46,7 @@ static inline Oid
 HeapTupleHeaderGetOidOld(const HeapTupleHeaderData *tup)
 {
    if (tup->t_infomask & HEAP_HASOID_OLD)
-       return *((Oid *) ((char *) (tup) + (tup)->t_hoff - sizeof(Oid)));
+       return *((const Oid *) ((const char *) (tup) + (tup)->t_hoff - sizeof(Oid)));
    else
        return InvalidOid;
 }
index 70e698f4ab37c7e6d43baf3e945856c9ed046ecf..aa4d0becace2c0ea60c774f9a9f92970df99ee5a 100644 (file)
@@ -337,7 +337,7 @@ uuid_generate_internal(int v, unsigned char *ns, const char *ptr, int len)
                        elog(ERROR, "could not initialize %s context: %s", "MD5",
                             pg_cryptohash_error(ctx));
                    if (pg_cryptohash_update(ctx, ns, sizeof(uu)) < 0 ||
-                       pg_cryptohash_update(ctx, (unsigned char *) ptr, len) < 0)
+                       pg_cryptohash_update(ctx, (const unsigned char *) ptr, len) < 0)
                        elog(ERROR, "could not update %s context: %s", "MD5",
                             pg_cryptohash_error(ctx));
                    /* we assume sizeof MD5 result is 16, same as UUID size */
@@ -356,7 +356,7 @@ uuid_generate_internal(int v, unsigned char *ns, const char *ptr, int len)
                        elog(ERROR, "could not initialize %s context: %s", "SHA1",
                             pg_cryptohash_error(ctx));
                    if (pg_cryptohash_update(ctx, ns, sizeof(uu)) < 0 ||
-                       pg_cryptohash_update(ctx, (unsigned char *) ptr, len) < 0)
+                       pg_cryptohash_update(ctx, (const unsigned char *) ptr, len) < 0)
                        elog(ERROR, "could not update %s context: %s", "SHA1",
                             pg_cryptohash_error(ctx));
                    if (pg_cryptohash_final(ctx, sha1result, sizeof(sha1result)) < 0)
index 1336328cc0b5758ec54747854bd9262959a10b5a..d449613b21f4fce910fa2d803d233bfbfeb49c06 100644 (file)
@@ -88,7 +88,7 @@ pglz_decompress_datum(const struct varlena *value)
    result = (struct varlena *) palloc(VARDATA_COMPRESSED_GET_EXTSIZE(value) + VARHDRSZ);
 
    /* decompress the data */
-   rawsize = pglz_decompress((char *) value + VARHDRSZ_COMPRESSED,
+   rawsize = pglz_decompress((const char *) value + VARHDRSZ_COMPRESSED,
                              VARSIZE(value) - VARHDRSZ_COMPRESSED,
                              VARDATA(result),
                              VARDATA_COMPRESSED_GET_EXTSIZE(value), true);
@@ -116,7 +116,7 @@ pglz_decompress_datum_slice(const struct varlena *value,
    result = (struct varlena *) palloc(slicelength + VARHDRSZ);
 
    /* decompress the data */
-   rawsize = pglz_decompress((char *) value + VARHDRSZ_COMPRESSED,
+   rawsize = pglz_decompress((const char *) value + VARHDRSZ_COMPRESSED,
                              VARSIZE(value) - VARHDRSZ_COMPRESSED,
                              VARDATA(result),
                              slicelength, false);
@@ -192,7 +192,7 @@ lz4_decompress_datum(const struct varlena *value)
    result = (struct varlena *) palloc(VARDATA_COMPRESSED_GET_EXTSIZE(value) + VARHDRSZ);
 
    /* decompress the data */
-   rawsize = LZ4_decompress_safe((char *) value + VARHDRSZ_COMPRESSED,
+   rawsize = LZ4_decompress_safe((const char *) value + VARHDRSZ_COMPRESSED,
                                  VARDATA(result),
                                  VARSIZE(value) - VARHDRSZ_COMPRESSED,
                                  VARDATA_COMPRESSED_GET_EXTSIZE(value));
@@ -229,7 +229,7 @@ lz4_decompress_datum_slice(const struct varlena *value, int32 slicelength)
    result = (struct varlena *) palloc(slicelength + VARHDRSZ);
 
    /* decompress the data */
-   rawsize = LZ4_decompress_safe_partial((char *) value + VARHDRSZ_COMPRESSED,
+   rawsize = LZ4_decompress_safe_partial((const char *) value + VARHDRSZ_COMPRESSED,
                                          VARDATA(result),
                                          VARSIZE(value) - VARHDRSZ_COMPRESSED,
                                          slicelength,
index 63eda08f7a2ac505787be3b6a6b2ca006b8dc475..d17aaa5aa0fb8179329d26625457cb0708adefab 100644 (file)
@@ -3023,8 +3023,8 @@ _bt_deadblocks(Page page, OffsetNumber *deletable, int ndeletable,
 static inline int
 _bt_blk_cmp(const void *arg1, const void *arg2)
 {
-   BlockNumber b1 = *((BlockNumber *) arg1);
-   BlockNumber b2 = *((BlockNumber *) arg2);
+   BlockNumber b1 = *((const BlockNumber *) arg1);
+   BlockNumber b2 = *((const BlockNumber *) arg2);
 
    return pg_cmp_u32(b1, b2);
 }
index 39e7749fe1635939c83bee7cc38d80b60bea8718..946dabc4527a76f9dcf7b5236a8e29ea3e2dd7b9 100644 (file)
@@ -147,8 +147,8 @@ spg_quad_choose(PG_FUNCTION_ARGS)
 static int
 x_cmp(const void *a, const void *b, void *arg)
 {
-   Point      *pa = *(Point **) a;
-   Point      *pb = *(Point **) b;
+   Point      *pa = *(Point *const *) a;
+   Point      *pb = *(Point *const *) b;
 
    if (pa->x == pb->x)
        return 0;
@@ -158,8 +158,8 @@ x_cmp(const void *a, const void *b, void *arg)
 static int
 y_cmp(const void *a, const void *b, void *arg)
 {
-   Point      *pa = *(Point **) a;
-   Point      *pb = *(Point **) b;
+   Point      *pa = *(Point *const *) a;
+   Point      *pb = *(Point *const *) b;
 
    if (pa->y == pb->y)
        return 0;
index 92c48e768c3d650706a73e51731aa80f5c36669f..f928bc7c0efa81ce035bb8a51387e04daa0e25a9 100644 (file)
@@ -677,8 +677,8 @@ XLogRecordAssemble(RmgrId rmid, uint8 info,
            if (regbuf->flags & REGBUF_STANDARD)
            {
                /* Assume we can omit data between pd_lower and pd_upper */
-               uint16      lower = ((PageHeader) page)->pd_lower;
-               uint16      upper = ((PageHeader) page)->pd_upper;
+               uint16      lower = ((const PageHeaderData *) page)->pd_lower;
+               uint16      upper = ((const PageHeaderData *) page)->pd_upper;
 
                if (lower >= SizeOfPageHeaderData &&
                    upper > lower &&
index c697caef895a30b4f09fe7d4aaeca780ce1c64a9..3760b00390779daed7f1755975ac61ce896524be 100644 (file)
@@ -388,7 +388,7 @@ AppendStringToManifest(backup_manifest_info *manifest, const char *s)
    Assert(manifest != NULL);
    if (manifest->still_checksumming)
    {
-       if (pg_cryptohash_update(manifest->manifest_ctx, (uint8 *) s, len) < 0)
+       if (pg_cryptohash_update(manifest->manifest_ctx, (const uint8 *) s, len) < 0)
            elog(ERROR, "failed to update checksum of backup manifest: %s",
                 pg_cryptohash_error(manifest->manifest_ctx));
    }
index ba06a38c0331049e99c19ccb406ff8d2c0e9b23a..463c0756b5e3dbd42cd55d0f95e83d8814048eaa 100644 (file)
@@ -1104,7 +1104,7 @@ sendFileWithContent(bbsink *sink, const char *filename, const char *content,
 
    _tarWriteHeader(sink, filename, NULL, &statbuf, false);
 
-   if (pg_checksum_update(&checksum_ctx, (uint8 *) content, len) < 0)
+   if (pg_checksum_update(&checksum_ctx, (const uint8 *) content, len) < 0)
        elog(ERROR, "could not update checksum of file \"%s\"",
             filename);
 
index 77dce24ad387b07ddab2d10cae48f7ba1def1f0b..f58ed9b198a48ec519da0575e4db19ae8e6e8244 100644 (file)
@@ -930,7 +930,7 @@ GetIncrementalFileSize(unsigned num_blocks_required)
 static uint32
 hash_string_pointer(const char *s)
 {
-   unsigned char *ss = (unsigned char *) s;
+   const unsigned char *ss = (const unsigned char *) s;
 
    return hash_bytes(ss, strlen(s));
 }
@@ -1049,8 +1049,8 @@ manifest_report_error(JsonManifestParseContext *context, const char *fmt,...)
 static int
 compare_block_numbers(const void *a, const void *b)
 {
-   BlockNumber aa = *(BlockNumber *) a;
-   BlockNumber bb = *(BlockNumber *) b;
+   BlockNumber aa = *(const BlockNumber *) a;
+   BlockNumber bb = *(const BlockNumber *) b;
 
    return pg_cmp_u32(aa, bb);
 }
index 84823f0b61518ebfa3faa3db3d4ab71594803c85..a616abff04cf03122b21bbec5f52f92e458dfdcf 100644 (file)
@@ -443,8 +443,8 @@ static int
 reorderqueue_cmp(const pairingheap_node *a, const pairingheap_node *b,
                 void *arg)
 {
-   ReorderTuple *rta = (ReorderTuple *) a;
-   ReorderTuple *rtb = (ReorderTuple *) b;
+   const ReorderTuple *rta = (const ReorderTuple *) a;
+   const ReorderTuple *rtb = (const ReorderTuple *) b;
    IndexScanState *node = (IndexScanState *) arg;
 
    /* exchange argument order to invert the sort order */
index 3c41145d9266b3f07e8816d35632654c54d46395..0267edb29cd9e7fd41f30bf3e41babad3a16993c 100644 (file)
@@ -1490,8 +1490,8 @@ scram_mock_salt(const char *username, pg_cryptohash_type hash_type,
 
    ctx = pg_cryptohash_create(hash_type);
    if (pg_cryptohash_init(ctx) < 0 ||
-       pg_cryptohash_update(ctx, (uint8 *) username, strlen(username)) < 0 ||
-       pg_cryptohash_update(ctx, (uint8 *) mock_auth_nonce, MOCK_AUTH_NONCE_LEN) < 0 ||
+       pg_cryptohash_update(ctx, (const uint8 *) username, strlen(username)) < 0 ||
+       pg_cryptohash_update(ctx, (const uint8 *) mock_auth_nonce, MOCK_AUTH_NONCE_LEN) < 0 ||
        pg_cryptohash_final(ctx, sha_digest, key_length) < 0)
    {
        pg_cryptohash_free(ctx);
index 4c1052b3d4282ed292b8917c34435799ac5c010a..52722060451b090965b07f3bdef736f5386a7cb3 100644 (file)
@@ -136,7 +136,7 @@ encrypt_password(PasswordType target_type, const char *role,
            case PASSWORD_TYPE_MD5:
                encrypted_password = palloc(MD5_PASSWD_LEN + 1);
 
-               if (!pg_md5_encrypt(password, (uint8 *) role, strlen(role),
+               if (!pg_md5_encrypt(password, (const uint8 *) role, strlen(role),
                                    encrypted_password, &errstr))
                    elog(ERROR, "password encryption failed: %s", errstr);
                break;
@@ -284,7 +284,7 @@ plain_crypt_verify(const char *role, const char *shadow_pass,
 
        case PASSWORD_TYPE_MD5:
            if (!pg_md5_encrypt(client_pass,
-                               (uint8 *) role,
+                               (const uint8 *) role,
                                strlen(role),
                                crypt_client_pass,
                                &errstr))
index d29664ca5d4e8f88509f98ded5b950345707fe00..199ed27995fc55fb6298fbe79ffbf1adf028ff36 100644 (file)
@@ -1009,14 +1009,14 @@ exprCollation(const Node *expr)
            break;
        case T_JsonExpr:
            {
-               const JsonExpr *jsexpr = (JsonExpr *) expr;
+               const JsonExpr *jsexpr = (const JsonExpr *) expr;
 
                coll = jsexpr->collation;
            }
            break;
        case T_JsonBehavior:
            {
-               const JsonBehavior *behavior = (JsonBehavior *) expr;
+               const JsonBehavior *behavior = (const JsonBehavior *) expr;
 
                if (behavior->expr)
                    coll = exprCollation(behavior->expr);
@@ -1593,7 +1593,7 @@ exprLocation(const Node *expr)
            }
            break;
        case T_JsonBehavior:
-           loc = exprLocation(((JsonBehavior *) expr)->expr);
+           loc = exprLocation(((const JsonBehavior *) expr)->expr);
            break;
        case T_NullTest:
            {
index c8eef2c75d218c7fc7e8b582564e7c659d92881f..40990143927e75e614b71b11de0cc3bcc35f9a4c 100644 (file)
@@ -736,17 +736,17 @@ outNode(StringInfo str, const void *obj)
        _outList(str, obj);
    /* nodeRead does not want to see { } around these! */
    else if (IsA(obj, Integer))
-       _outInteger(str, (Integer *) obj);
+       _outInteger(str, (const Integer *) obj);
    else if (IsA(obj, Float))
-       _outFloat(str, (Float *) obj);
+       _outFloat(str, (const Float *) obj);
    else if (IsA(obj, Boolean))
-       _outBoolean(str, (Boolean *) obj);
+       _outBoolean(str, (const Boolean *) obj);
    else if (IsA(obj, String))
-       _outString(str, (String *) obj);
+       _outString(str, (const String *) obj);
    else if (IsA(obj, BitString))
-       _outBitString(str, (BitString *) obj);
+       _outBitString(str, (const BitString *) obj);
    else if (IsA(obj, Bitmapset))
-       outBitmapset(str, (Bitmapset *) obj);
+       outBitmapset(str, (const Bitmapset *) obj);
    else
    {
        appendStringInfoChar(str, '{');
index 805ff21c7f10baeeef74cd6649c3ec3256d83988..f1f925cb13b99b360bd801e683c054d75c8ec2dc 100644 (file)
@@ -1439,8 +1439,8 @@ static int
 tbm_shared_comparator(const void *left, const void *right, void *arg)
 {
    PagetableEntry *base = (PagetableEntry *) arg;
-   PagetableEntry *lpage = &base[*(int *) left];
-   PagetableEntry *rpage = &base[*(int *) right];
+   PagetableEntry *lpage = &base[*(const int *) left];
+   PagetableEntry *rpage = &base[*(const int *) right];
 
    if (lpage->blockno < rpage->blockno)
        return -1;
index b9a8f257042267d0503730f5186396ba8fc913c4..3895ed72ef75fe4a0971525bf6634f1f6663247b 100644 (file)
@@ -915,8 +915,8 @@ multi_sort_compare_dims(int start, int end,
 int
 compare_scalars_simple(const void *a, const void *b, void *arg)
 {
-   return compare_datums_simple(*(Datum *) a,
-                                *(Datum *) b,
+   return compare_datums_simple(*(const Datum *) a,
+                                *(const Datum *) b,
                                 (SortSupport) arg);
 }
 
index 4d6cc16c0bc74c73d061be9d2328355521f42edf..3ce6068ac54f6fcefed24c5dd465a11e81cbdcab 100644 (file)
@@ -1041,7 +1041,7 @@ shm_mq_send_bytes(shm_mq_handle *mqh, Size nbytes, const void *data,
             */
            pg_memory_barrier();
            memcpy(&mq->mq_ring[mq->mq_ring_offset + offset],
-                  (char *) data + sent, sendnow);
+                  (const char *) data + sent, sendnow);
            sent += sendnow;
 
            /*
index e3436dbddd2dc5e0993bb8152f3e719a7982b4f8..ad0ceec37b04b893a058fdb0cd48d6d01c952be1 100644 (file)
@@ -2463,9 +2463,9 @@ SplitToVariants(IspellDict *Conf, SPNode *snode, SplitVar *orig, const char *wor
        while (StopLow < StopHigh)
        {
            StopMiddle = StopLow + ((StopHigh - StopLow) >> 1);
-           if (StopMiddle->val == ((uint8 *) (word))[level])
+           if (StopMiddle->val == ((const uint8 *) (word))[level])
                break;
-           else if (StopMiddle->val < ((uint8 *) (word))[level])
+           else if (StopMiddle->val < ((const uint8 *) (word))[level])
                StopLow = StopMiddle + 1;
            else
                StopHigh = StopMiddle;
index 19bcae3848b696a5474af8dffccea1bae45075b2..7a19ca3892b440be9f026a05b5b989ac04f60bfd 100644 (file)
@@ -92,8 +92,8 @@
 static int
 compareDoubles(const void *a, const void *b)
 {
-   float8      x = *(float8 *) a;
-   float8      y = *(float8 *) b;
+   float8      x = *(const float8 *) a;
+   float8      y = *(const float8 *) b;
 
    if (x == y)
        return 0;
index 78e84727fdc8e3687ed5f2c2862b0d7415bd5c6c..0b16139846535f0d55baa0cf8f23a9533eb64b45 100644 (file)
@@ -901,7 +901,7 @@ json_agg_finalfn(PG_FUNCTION_ARGS)
 static uint32
 json_unique_hash(const void *key, Size keysize)
 {
-   const JsonUniqueHashEntry *entry = (JsonUniqueHashEntry *) key;
+   const JsonUniqueHashEntry *entry = (const JsonUniqueHashEntry *) key;
    uint32      hash = hash_bytes_uint32(entry->object_id);
 
    hash ^= hash_bytes((const unsigned char *) entry->key, entry->key_len);
index 1f5fc1c97f3233ab4a796d5090312f74fc54af9b..b5aeb7a337a9f013f6760a3bfa182dd55555c2cd 100644 (file)
@@ -63,7 +63,7 @@ initcap_wbnext(void *state)
    while (wbstate->offset < wbstate->len &&
           wbstate->str[wbstate->offset] != '\0')
    {
-       char32_t    u = utf8_to_unicode((unsigned char *) wbstate->str +
+       char32_t    u = utf8_to_unicode((const unsigned char *) wbstate->str +
                                        wbstate->offset);
        bool        curr_alnum = pg_u_isalnum(u, wbstate->posix);
 
index 701aacbbfb05aa1baf10e717d1f8c14cbded5406..06cc3af4f4ac868d05ab1d4e60a55f7847a5c380 100644 (file)
@@ -2108,7 +2108,7 @@ range_deserialize(TypeCacheEntry *typcache, const RangeType *range,
    typalign = typcache->rngelemtype->typalign;
 
    /* initialize data pointer just after the range OID */
-   ptr = (char *) (range + 1);
+   ptr = (const char *) (range + 1);
 
    /* fetch lower bound, if any */
    if (RANGE_HAS_LBOUND(flags))
@@ -2155,7 +2155,7 @@ char
 range_get_flags(const RangeType *range)
 {
    /* fetch the flag byte from datum's last byte */
-   return *((char *) range + VARSIZE(range) - 1);
+   return *((const char *) range + VARSIZE(range) - 1);
 }
 
 /*
@@ -2360,8 +2360,8 @@ range_cmp_bound_values(TypeCacheEntry *typcache, const RangeBound *b1,
 int
 range_compare(const void *key1, const void *key2, void *arg)
 {
-   RangeType  *r1 = *(RangeType **) key1;
-   RangeType  *r2 = *(RangeType **) key2;
+   RangeType  *r1 = *(RangeType *const *) key1;
+   RangeType  *r2 = *(RangeType *const *) key2;
    TypeCacheEntry *typcache = (TypeCacheEntry *) arg;
    RangeBound  lower1;
    RangeBound  upper1;
index cb9f769cdb21bc818c1ea43fc32ee2ddc9b5694b..1a01a8f4c3cc5010a9cd2301f63a81dcf221e407 100644 (file)
@@ -1768,8 +1768,8 @@ interval_cmp_upper(const void *a, const void *b, void *arg)
 static int
 common_entry_cmp(const void *i1, const void *i2)
 {
-   double      delta1 = ((CommonEntry *) i1)->delta;
-   double      delta2 = ((CommonEntry *) i2)->delta;
+   double      delta1 = ((const CommonEntry *) i1)->delta;
+   double      delta2 = ((const CommonEntry *) i2)->delta;
 
    if (delta1 < delta2)
        return -1;
index f6e2371f4777b6dad3e549878d8de39158f056cd..17d22c79f68a037b8f5ec4917076a0dadb7585f6 100644 (file)
@@ -359,7 +359,7 @@ dir_write(Walfile *f, const void *buf, size_t count)
                return -1;
            }
 
-           inbuf = ((char *) inbuf) + chunk;
+           inbuf = ((const char *) inbuf) + chunk;
        }
 
        /* Our caller keeps track of the uncompressed size. */
index 2610bae7e098370a653bec6d4b1babef5e16b329..b79c47f925266ef9c8e23500c08905f675c0cf50 100644 (file)
@@ -694,8 +694,8 @@ datasegpath(RelFileLocator rlocator, ForkNumber forknum, BlockNumber segno)
 static int
 final_filemap_cmp(const void *a, const void *b)
 {
-   file_entry_t *fa = *((file_entry_t **) a);
-   file_entry_t *fb = *((file_entry_t **) b);
+   file_entry_t *fa = *((file_entry_t *const *) a);
+   file_entry_t *fb = *((file_entry_t *const *) b);
 
    if (fa->action > fb->action)
        return 1;
index 440c96269d71b47f5fa14dd81b2d3b75d4e3e136..0edc8123b43fb36623d4863c9073e57517afce3a 100644 (file)
@@ -268,7 +268,7 @@ member_compute_checksum(astreamer *streamer, astreamer_member *member,
    mystreamer->checksum_bytes += len;
 
    /* Feed these bytes to the checksum calculation. */
-   if (pg_checksum_update(checksum_ctx, (uint8 *) data, len) < 0)
+   if (pg_checksum_update(checksum_ctx, (const uint8 *) data, len) < 0)
    {
        report_backup_error(mystreamer->context,
                            "could not update checksum of file \"%s\"",
index 74851f84f92567422a5a6bb34e37c06db5fb63e8..aa214b8616de34f213a1085259f88213433a7a85 100644 (file)
@@ -217,8 +217,8 @@ dump_one_relation(ws_options *opt, RelFileLocator *rlocator,
 static int
 compare_block_numbers(const void *a, const void *b)
 {
-   BlockNumber aa = *(BlockNumber *) a;
-   BlockNumber bb = *(BlockNumber *) b;
+   BlockNumber aa = *(const BlockNumber *) a;
+   BlockNumber bb = *(const BlockNumber *) b;
 
    return pg_cmp_u32(aa, bb);
 }
index dbf188ae87228df07416192de6168c6f753cb432..259fa5554b602ba574dd39a129da07d663431708 100644 (file)
@@ -61,7 +61,7 @@ scram_SaltedPassword(const char *password,
     */
 
    /* First iteration */
-   if (pg_hmac_init(hmac_ctx, (uint8 *) password, password_len) < 0 ||
+   if (pg_hmac_init(hmac_ctx, (const uint8 *) password, password_len) < 0 ||
        pg_hmac_update(hmac_ctx, salt, saltlen) < 0 ||
        pg_hmac_update(hmac_ctx, (uint8 *) &one, sizeof(uint32)) < 0 ||
        pg_hmac_final(hmac_ctx, Ui_prev, key_length) < 0)
@@ -84,7 +84,7 @@ scram_SaltedPassword(const char *password,
        CHECK_FOR_INTERRUPTS();
 #endif
 
-       if (pg_hmac_init(hmac_ctx, (uint8 *) password, password_len) < 0 ||
+       if (pg_hmac_init(hmac_ctx, (const uint8 *) password, password_len) < 0 ||
            pg_hmac_update(hmac_ctx, (uint8 *) Ui_prev, key_length) < 0 ||
            pg_hmac_final(hmac_ctx, Ui, key_length) < 0)
        {
index 2144219e178fe09e991a1680f7b886bcb21684db..fb159c1c27caf47eb85218733bb7ee700954288e 100644 (file)
@@ -55,7 +55,7 @@ initcap_wbnext(void *state)
    while (wbstate->offset < wbstate->len &&
           wbstate->str[wbstate->offset] != '\0')
    {
-       char32_t    u = utf8_to_unicode((unsigned char *) wbstate->str +
+       char32_t    u = utf8_to_unicode((const unsigned char *) wbstate->str +
                                        wbstate->offset);
        bool        curr_alnum = pg_u_isalnum(u, wbstate->posix);
 
index 71acd38d6fe19a5b37f8fae53f19919c9c02cd6b..0b8d3ffc0b4dd6d3383962a1e429543ead123557 100644 (file)
@@ -231,7 +231,7 @@ convert_case(char *dst, size_t dstsize, const char *src, ssize_t srclen,
 
    while ((srclen < 0 || srcoff < srclen) && src[srcoff] != '\0')
    {
-       char32_t    u1 = utf8_to_unicode((unsigned char *) src + srcoff);
+       char32_t    u1 = utf8_to_unicode((const unsigned char *) src + srcoff);
        int         u1len = unicode_utf8len(u1);
        char32_t    simple = 0;
        const char32_t *special = NULL;
@@ -373,7 +373,7 @@ check_special_conditions(int conditions, const char *str, size_t len,
    if (conditions == 0)
        return true;
    else if (conditions == PG_U_FINAL_SIGMA)
-       return check_final_sigma((unsigned char *) str, len, offset);
+       return check_final_sigma((const unsigned char *) str, len, offset);
 
    /* no other conditions supported */
    Assert(false);
index e6df8264750a4fb5d236b03dce6b7fda81ef6d1b..3e5530658c9471aed48091f419396fc085bd6ce4 100644 (file)
@@ -190,7 +190,7 @@ fetch_att(const void *T, bool attbyval, int attlen)
    : \
    ( \
        AssertMacro((attlen) == -2), \
-       (cur_offset) + (strlen((char *) (attptr)) + 1) \
+       (cur_offset) + (strlen((const char *) (attptr)) + 1) \
    )) \
 )
 
index 5214b86155086996acdf6b586524a1d9bb669197..6966daa2b09431e8a605f41f88dc80dd2678c058 100644 (file)
@@ -271,7 +271,7 @@ fasthash_accum_cstring_aligned(fasthash_state *hs, const char *str)
     */
    for (;;)
    {
-       uint64      chunk = *(uint64 *) str;
+       uint64      chunk = *(const uint64 *) str;
 
        zero_byte_low = haszero64(chunk);
        if (zero_byte_low)
index 2bc13c3a0540d4d4409850cd7dd3f8bf127f747c..11ab1717a16266457eeaab4edcb9259bf1c4091d 100644 (file)
@@ -253,7 +253,7 @@ pg_memory_is_all_zeros(const void *ptr, size_t len)
         */
        for (; p < aligned_end; p += sizeof(size_t))
        {
-           if (*(size_t *) p != 0)
+           if (*(const size_t *) p != 0)
                return false;
        }
 
@@ -290,10 +290,10 @@ pg_memory_is_all_zeros(const void *ptr, size_t len)
     */
    for (; p < aligned_end - (sizeof(size_t) * 7); p += sizeof(size_t) * 8)
    {
-       if ((((size_t *) p)[0] != 0) | (((size_t *) p)[1] != 0) |
-           (((size_t *) p)[2] != 0) | (((size_t *) p)[3] != 0) |
-           (((size_t *) p)[4] != 0) | (((size_t *) p)[5] != 0) |
-           (((size_t *) p)[6] != 0) | (((size_t *) p)[7] != 0))
+       if ((((const size_t *) p)[0] != 0) | (((const size_t *) p)[1] != 0) |
+           (((const size_t *) p)[2] != 0) | (((const size_t *) p)[3] != 0) |
+           (((const size_t *) p)[4] != 0) | (((const size_t *) p)[5] != 0) |
+           (((const size_t *) p)[6] != 0) | (((const size_t *) p)[7] != 0))
            return false;
    }
 
@@ -305,7 +305,7 @@ pg_memory_is_all_zeros(const void *ptr, size_t len)
     */
    for (; p < aligned_end; p += sizeof(size_t))
    {
-       if (*(size_t *) p != 0)
+       if (*(const size_t *) p != 0)
            return false;
    }
 
index eccd3ca04d667c70d1ee8f5bc1e9f04312e57747..fd7d5912f7d3fbd5b3a777571371a90d02bdfbf0 100644 (file)
@@ -193,25 +193,25 @@ typedef struct
 #ifdef WORDS_BIGENDIAN
 
 #define VARATT_IS_4B(PTR) \
-   ((((varattrib_1b *) (PTR))->va_header & 0x80) == 0x00)
+   ((((const varattrib_1b *) (PTR))->va_header & 0x80) == 0x00)
 #define VARATT_IS_4B_U(PTR) \
-   ((((varattrib_1b *) (PTR))->va_header & 0xC0) == 0x00)
+   ((((const varattrib_1b *) (PTR))->va_header & 0xC0) == 0x00)
 #define VARATT_IS_4B_C(PTR) \
-   ((((varattrib_1b *) (PTR))->va_header & 0xC0) == 0x40)
+   ((((const varattrib_1b *) (PTR))->va_header & 0xC0) == 0x40)
 #define VARATT_IS_1B(PTR) \
-   ((((varattrib_1b *) (PTR))->va_header & 0x80) == 0x80)
+   ((((const varattrib_1b *) (PTR))->va_header & 0x80) == 0x80)
 #define VARATT_IS_1B_E(PTR) \
-   ((((varattrib_1b *) (PTR))->va_header) == 0x80)
+   ((((const varattrib_1b *) (PTR))->va_header) == 0x80)
 #define VARATT_NOT_PAD_BYTE(PTR) \
-   (*((uint8 *) (PTR)) != 0)
+   (*((const uint8 *) (PTR)) != 0)
 
 /* VARSIZE_4B() should only be used on known-aligned data */
 #define VARSIZE_4B(PTR) \
-   (((varattrib_4b *) (PTR))->va_4byte.va_header & 0x3FFFFFFF)
+   (((const varattrib_4b *) (PTR))->va_4byte.va_header & 0x3FFFFFFF)
 #define VARSIZE_1B(PTR) \
-   (((varattrib_1b *) (PTR))->va_header & 0x7F)
+   (((const varattrib_1b *) (PTR))->va_header & 0x7F)
 #define VARTAG_1B_E(PTR) \
-   ((vartag_external) ((varattrib_1b_e *) (PTR))->va_tag)
+   ((vartag_external) ((const varattrib_1b_e *) (PTR))->va_tag)
 
 #define SET_VARSIZE_4B(PTR,len) \
    (((varattrib_4b *) (PTR))->va_4byte.va_header = (len) & 0x3FFFFFFF)
@@ -226,25 +226,25 @@ typedef struct
 #else                          /* !WORDS_BIGENDIAN */
 
 #define VARATT_IS_4B(PTR) \
-   ((((varattrib_1b *) (PTR))->va_header & 0x01) == 0x00)
+   ((((const varattrib_1b *) (PTR))->va_header & 0x01) == 0x00)
 #define VARATT_IS_4B_U(PTR) \
-   ((((varattrib_1b *) (PTR))->va_header & 0x03) == 0x00)
+   ((((const varattrib_1b *) (PTR))->va_header & 0x03) == 0x00)
 #define VARATT_IS_4B_C(PTR) \
-   ((((varattrib_1b *) (PTR))->va_header & 0x03) == 0x02)
+   ((((const varattrib_1b *) (PTR))->va_header & 0x03) == 0x02)
 #define VARATT_IS_1B(PTR) \
-   ((((varattrib_1b *) (PTR))->va_header & 0x01) == 0x01)
+   ((((const varattrib_1b *) (PTR))->va_header & 0x01) == 0x01)
 #define VARATT_IS_1B_E(PTR) \
-   ((((varattrib_1b *) (PTR))->va_header) == 0x01)
+   ((((const varattrib_1b *) (PTR))->va_header) == 0x01)
 #define VARATT_NOT_PAD_BYTE(PTR) \
-   (*((uint8 *) (PTR)) != 0)
+   (*((const uint8 *) (PTR)) != 0)
 
 /* VARSIZE_4B() should only be used on known-aligned data */
 #define VARSIZE_4B(PTR) \
-   ((((varattrib_4b *) (PTR))->va_4byte.va_header >> 2) & 0x3FFFFFFF)
+   ((((const varattrib_4b *) (PTR))->va_4byte.va_header >> 2) & 0x3FFFFFFF)
 #define VARSIZE_1B(PTR) \
-   ((((varattrib_1b *) (PTR))->va_header >> 1) & 0x7F)
+   ((((const varattrib_1b *) (PTR))->va_header >> 1) & 0x7F)
 #define VARTAG_1B_E(PTR) \
-   ((vartag_external) ((varattrib_1b_e *) (PTR))->va_tag)
+   ((vartag_external) ((const varattrib_1b_e *) (PTR))->va_tag)
 
 #define SET_VARSIZE_4B(PTR,len) \
    (((varattrib_4b *) (PTR))->va_4byte.va_header = (((uint32) (len)) << 2))
@@ -492,14 +492,14 @@ VARDATA_ANY(const void *PTR)
 static inline Size
 VARDATA_COMPRESSED_GET_EXTSIZE(const void *PTR)
 {
-   return ((varattrib_4b *) PTR)->va_compressed.va_tcinfo & VARLENA_EXTSIZE_MASK;
+   return ((const varattrib_4b *) PTR)->va_compressed.va_tcinfo & VARLENA_EXTSIZE_MASK;
 }
 
 /* Compression method of a compressed-in-line varlena datum */
 static inline uint32
 VARDATA_COMPRESSED_GET_COMPRESS_METHOD(const void *PTR)
 {
-   return ((varattrib_4b *) PTR)->va_compressed.va_tcinfo >> VARLENA_EXTSIZE_BITS;
+   return ((const varattrib_4b *) PTR)->va_compressed.va_tcinfo >> VARLENA_EXTSIZE_BITS;
 }
 
 /* Same for external Datums; but note argument is a struct varatt_external */
index 05273c91f98cd78a3088326bab762c21137c7520..99103b7e2b66779ddefcf706d753b3af653bbbcd 100644 (file)
@@ -819,7 +819,7 @@ calculate_client_proof(fe_scram_state *state,
                       strlen(state->server_first_message)) < 0 ||
        pg_hmac_update(ctx, (uint8 *) ",", 1) < 0 ||
        pg_hmac_update(ctx,
-                      (uint8 *) client_final_message_without_proof,
+                      (const uint8 *) client_final_message_without_proof,
                       strlen(client_final_message_without_proof)) < 0 ||
        pg_hmac_final(ctx, ClientSignature, state->key_length) < 0)
    {
index f08db30dbb773c266cd9b322f727a76aee88f62e..f05aaea96510a9726f1c2b220cf30ddea576d4e4 100644 (file)
@@ -1369,7 +1369,7 @@ PQencryptPassword(const char *passwd, const char *user)
    if (!crypt_pwd)
        return NULL;
 
-   if (!pg_md5_encrypt(passwd, (uint8 *) user, strlen(user), crypt_pwd, &errstr))
+   if (!pg_md5_encrypt(passwd, (const uint8 *) user, strlen(user), crypt_pwd, &errstr))
    {
        free(crypt_pwd);
        return NULL;
@@ -1482,7 +1482,7 @@ PQencryptPasswordConn(PGconn *conn, const char *passwd, const char *user,
        {
            const char *errstr = NULL;
 
-           if (!pg_md5_encrypt(passwd, (uint8 *) user, strlen(user), crypt_pwd, &errstr))
+           if (!pg_md5_encrypt(passwd, (const uint8 *) user, strlen(user), crypt_pwd, &errstr))
            {
                libpq_append_conn_error(conn, "could not encrypt password: %s", errstr);
                free(crypt_pwd);
index 039986c7b33fce78a7bd1c353871527d681413fb..9ca0f728d398520bed505ff420d3b3742c8773de 100644 (file)
@@ -42,32 +42,32 @@ pg_comp_crc32c_armv8(pg_crc32c crc, const void *data, size_t len)
    if (!PointerIsAligned(p, uint32) &&
        p + 2 <= pend)
    {
-       crc = __crc32ch(crc, *(uint16 *) p);
+       crc = __crc32ch(crc, *(const uint16 *) p);
        p += 2;
    }
    if (!PointerIsAligned(p, uint64) &&
        p + 4 <= pend)
    {
-       crc = __crc32cw(crc, *(uint32 *) p);
+       crc = __crc32cw(crc, *(const uint32 *) p);
        p += 4;
    }
 
    /* Process eight bytes at a time, as far as we can. */
    while (p + 8 <= pend)
    {
-       crc = __crc32cd(crc, *(uint64 *) p);
+       crc = __crc32cd(crc, *(const uint64 *) p);
        p += 8;
    }
 
    /* Process remaining 0-7 bytes. */
    if (p + 4 <= pend)
    {
-       crc = __crc32cw(crc, *(uint32 *) p);
+       crc = __crc32cw(crc, *(const uint32 *) p);
        p += 4;
    }
    if (p + 2 <= pend)
    {
-       crc = __crc32ch(crc, *(uint16 *) p);
+       crc = __crc32ch(crc, *(const uint16 *) p);
        p += 2;
    }
    if (p < pend)
index 2184854dbf7faf5749b8f5013d5c3d83d892dc57..ba57f2cd4bd6295d06fb11cb299aba44163db946 100644 (file)
@@ -383,7 +383,7 @@ pg_popcount_neon(const char *buf, int bytes)
     */
    for (; bytes >= sizeof(uint64); bytes -= sizeof(uint64))
    {
-       popcnt += pg_popcount64(*((uint64 *) buf));
+       popcnt += pg_popcount64(*((const uint64 *) buf));
        buf += sizeof(uint64);
    }
 
@@ -465,7 +465,7 @@ pg_popcount_masked_neon(const char *buf, int bytes, bits8 mask)
     */
    for (; bytes >= sizeof(uint64); bytes -= sizeof(uint64))
    {
-       popcnt += pg_popcount64(*((uint64 *) buf) & mask64);
+       popcnt += pg_popcount64(*((const uint64 *) buf) & mask64);
        buf += sizeof(uint64);
    }
 
index e01c0c9de936e70f7fdb6cc2b5e005af2e613150..a0aec04d994e45af10a01f3d8f717f0ef8f0f670 100644 (file)
@@ -498,8 +498,8 @@ run_named_permutations(TestSpec *testspec)
 static int
 step_qsort_cmp(const void *a, const void *b)
 {
-   Step       *stepa = *((Step **) a);
-   Step       *stepb = *((Step **) b);
+   Step       *stepa = *((Step *const *) a);
+   Step       *stepb = *((Step *const *) b);
 
    return strcmp(stepa->name, stepb->name);
 }
@@ -507,8 +507,8 @@ step_qsort_cmp(const void *a, const void *b)
 static int
 step_bsearch_cmp(const void *a, const void *b)
 {
-   char       *stepname = (char *) a;
-   Step       *step = *((Step **) b);
+   const char *stepname = (const char *) a;
+   Step       *step = *((Step *const *) b);
 
    return strcmp(stepname, step->name);
 }
index 0fb44be32ced4d5198a3b3bd41bac5fff4cff04a..ce1a9995f4656bb1cb248de9defa7ae7b06b095e 100644 (file)
@@ -1594,7 +1594,7 @@ test_singlerowmode(PGconn *conn)
                              "SELECT generate_series(42, $1)",
                              1,
                              NULL,
-                             (const char **) param,
+                             (const char *const *) param,
                              NULL,
                              NULL,
                              0) != 1)
index 9a3a209da0b37155c928799d00ac5efdfa0dab73..c9a035fa4941644b898133a0e1f2ca26acdac5f8 100644 (file)
@@ -56,16 +56,16 @@ itemptr_cmp(const void *left, const void *right)
    OffsetNumber loff,
                roff;
 
-   lblk = ItemPointerGetBlockNumber((ItemPointer) left);
-   rblk = ItemPointerGetBlockNumber((ItemPointer) right);
+   lblk = ItemPointerGetBlockNumber((const ItemPointerData *) left);
+   rblk = ItemPointerGetBlockNumber((const ItemPointerData *) right);
 
    if (lblk < rblk)
        return -1;
    if (lblk > rblk)
        return 1;
 
-   loff = ItemPointerGetOffsetNumber((ItemPointer) left);
-   roff = ItemPointerGetOffsetNumber((ItemPointer) right);
+   loff = ItemPointerGetOffsetNumber((const ItemPointerData *) left);
+   roff = ItemPointerGetOffsetNumber((const ItemPointerData *) right);
 
    if (loff < roff)
        return -1;