Avoid suspects casts VARHDRSZ (c.h)

Started by Ranier Vilelaalmost 6 years ago2 messageshackers
Beta feature

Hackorum builds and tests every patch posted to the lists, not only commitfest submissions. This is Hackorum's own CI rather than the PostgreSQL project's, and it is still under testing - please report anything that looks wrong.

appliessuccessCI history

You can run a PostgreSQL built from this patch straight from Docker, with no checkout and no build:

docker run --rm -p 5432:5432 ghcr.io/hackorum-dev/postgres-patch:t42996
psql -h localhost -U postgres

Built from patchset v1 (message #1), September 20, 2026 at 12:06 PM.

Every patchset is also pushed to a branch of our PostgreSQL fork, so you can check out the same tree CI built. Without a PostgreSQL checkout:

git clone --branch t42996_1 https://github.com/hackorum-dev/postgres.git

In a checkout you already have, add the fork once:

git remote add hackorum https://github.com/hackorum-dev/postgres.git

then, for this patchset and every later one:

git fetch hackorum t42996_1 && git checkout t42996_1

Patchset v1 (message #1) is on t42996_1

Jump to latest
#1Ranier Vilela
ranier.vf@gmail.com

Hi,

In all the static analysis tools I’ve used, there are literally *hundreds*
of alerts about a one suspect cast:

64 bits sizet_t -> 32 bits int -> 64 bits size_t
-#define VARHDRSZ ((int32) sizeof(int32))
+#define VARHDRSZ (sizeof(int32))

Is there any special reason for not simplifying this and avoiding these
alerts?
Passed 100% with vcregress check and in use in local tests.

regards,
Ranier Vilela

Attachments:

t42996_1
avoid_suspects_cast_VARHDRSZ.patchapplication/octet-stream; name=avoid_suspects_cast_VARHDRSZ.patchDownload+1-1
#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Ranier Vilela (#1)
Re: Avoid suspects casts VARHDRSZ (c.h)

Ranier Vilela <ranier.vf@gmail.com> writes:

In all the static analysis tools I’ve used, there are literally *hundreds*
of alerts about a one suspect cast:

64 bits sizet_t -> 32 bits int -> 64 bits size_t
-#define VARHDRSZ ((int32) sizeof(int32))
+#define VARHDRSZ (sizeof(int32))

Given that the compiler can very easily see that there is no actual
overflow there, I question whether these warnings are of any value.

Also, the proposed patch changes the type of that macro from signed
to unsigned, meaning that it's considerably riskier than you seem
to think. We'd have to look at every usage to see if that would
affect the interpretation of any comparisons, for example.

On the whole I see little value here.
Suggest finding a tool with less nanny-ish tendencies.

regards, tom lane