Fix incorrect const qualification for tbm_add_tuples() and itemptr_to_uint64() - Mailing list pgsql-hackers

From Chao Li
Subject Fix incorrect const qualification for tbm_add_tuples() and itemptr_to_uint64()
Date
Msg-id CAEoWx2m2E0xE8Kvbkv31ULh_E+5zph-WA_bEdv3UR9CLhw+3vg@mail.gmail.com
Whole thread Raw
List pgsql-hackers
Hi Hackers,

I noticed a wrong const qualification:
```
void
tbm_add_tuples(TIDBitmap *tbm, const ItemPointer tids, int ntids,
  bool recheck)
```

This "const" only protects "tids" itself from updating, which is meaningless. I believe the real intention should be protecting the content "tids" pointing to from updating.

This behavior can be easily proved by the compiler. If we add a line of fake code in the function:
```
tids[0].ip_posid = 0;
```

With current "const ItemPointer tids", the compiler won't report any problem. If we change to "const ItemPointerData *tids", the compiler will raise an error due to the assignment to read-only variable.

I searched over the source tree, and found only one more occurrence in itemptr_to_uint64(), so I fixed it as well.

Also, as I am touching tbm_add_tuples(), I did a tiny change that moved the loop variable "i" into "for". Peter Eisentraut just did the same change in formatting.c [1].


Best regards,
Chao Li (Evan)
---------------------
HighGo Software Co., Ltd.
https://www.highgo.com/
Attachment

pgsql-hackers by date:

Previous
From: jian he
Date:
Subject: Re: postgres_fdw: Use COPY to speed up batch inserts
Next
From: Chao Li
Date:
Subject: Remove meaningless const qualifier from ginCompressPostingList()