Miroslav Lichvar
2013-04-02 15:01:35 UTC
When compiling the linuxptp sources with -O2 (gcc 4.7.2), I get a
number of warnings. There are some "may be used uninitialized in this
function" and some "dereferencing type-punned pointer will break
strict-aliasing rules" warnings. What's the policy for warnings?
Should -O2 be used by default?
With this patch the strict-aliasing warnings are gone, but I'm not
sure if that really fixes the problem or confuses the compiler to not
detect the problem (or fixes a false positive).
--- a/phc2sys.c
+++ b/phc2sys.c
@@ -330,12 +330,14 @@ static int is_msg_mgt(struct ptp_message *msg)
static int get_mgt_id(struct ptp_message *msg)
{
- return ((struct management_tlv *) msg->management.suffix)->id;
+ struct management_tlv *mgt = (struct management_tlv *) msg->management.suffix;
+ return mgt->id;
}
static void *get_mgt_data(struct ptp_message *msg)
{
- return ((struct management_tlv *) msg->management.suffix)->data;
+ struct management_tlv *mgt = (struct management_tlv *) msg->management.suffix;
+ return mgt->data;
}
Thanks,
number of warnings. There are some "may be used uninitialized in this
function" and some "dereferencing type-punned pointer will break
strict-aliasing rules" warnings. What's the policy for warnings?
Should -O2 be used by default?
With this patch the strict-aliasing warnings are gone, but I'm not
sure if that really fixes the problem or confuses the compiler to not
detect the problem (or fixes a false positive).
--- a/phc2sys.c
+++ b/phc2sys.c
@@ -330,12 +330,14 @@ static int is_msg_mgt(struct ptp_message *msg)
static int get_mgt_id(struct ptp_message *msg)
{
- return ((struct management_tlv *) msg->management.suffix)->id;
+ struct management_tlv *mgt = (struct management_tlv *) msg->management.suffix;
+ return mgt->id;
}
static void *get_mgt_data(struct ptp_message *msg)
{
- return ((struct management_tlv *) msg->management.suffix)->data;
+ struct management_tlv *mgt = (struct management_tlv *) msg->management.suffix;
+ return mgt->data;
}
Thanks,
--
Miroslav Lichvar
Miroslav Lichvar