Avoid suspects casts VARHDRSZ (c.h)
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:
avoid_suspects_cast_VARHDRSZ.patchapplication/octet-stream; name=avoid_suspects_cast_VARHDRSZ.patchDownload
diff --git a/src/include/c.h b/src/include/c.h
index 2c61ca8aa8..b768d6fcf1 100644
--- a/src/include/c.h
+++ b/src/include/c.h
@@ -565,7 +565,7 @@ struct varlena
char vl_dat[FLEXIBLE_ARRAY_MEMBER]; /* Data content is here */
};
-#define VARHDRSZ ((int32) sizeof(int32))
+#define VARHDRSZ (sizeof(int32))
/*
* These widely-used datatypes are just a varlena header and the data bytes.
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