From: Neil Brown <neilb@suse.de>
To: Luca Berra <bluca@comedia.it>
Cc: "linux-raid@vger.kernel.org" <linux-raid@vger.kernel.org>
Subject: Re: [mdadm PATCH 1/3] fix gcc warnings about strict-aliasing rules
Date: Wed, 3 Mar 2010 15:19:57 +1100 [thread overview]
Message-ID: <20100303151957.217fdf0b@notabene.brown> (raw)
In-Reply-To: <20100302074811.GC28827@maude.comedia.it>
On Tue, 2 Mar 2010 08:48:11 +0100
Luca Berra <bluca@comedia.it> wrote:
> On Tue, Mar 02, 2010 at 10:40:21AM +0300, Michael Tokarev wrote:
> >Luca Berra wrong:
> >> Signed-off-by: Luca Berra <bluca@comedia.it>
> >> ---
> >> util.c | 4 ++--
> >> 1 files changed, 2 insertions(+), 2 deletions(-)
> >>
> >> diff --git a/util.c b/util.c
> >> index 68f048d..1def2a0 100644
> >> --- a/util.c
> >> +++ b/util.c
> >> @@ -1160,7 +1160,7 @@ static int get_gpt_last_partition_end(int fd,
> >> unsigned long long *endofpart)
> >> entry_size = __le32_to_cpu(buf[GPT_ENTRY_SIZE_OFFSET]);
> >> /* Check GPT signature*/
> >> - if (*((__u64*)buf) != GPT_SIGNATURE_MAGIC)
> >> + if ((__u64)buf[0] != GPT_SIGNATURE_MAGIC)
> >
> >This looks wrong.
> >
> >buf is an array of unsigned char. Before, we converted the
> >whole thing to a pointer to u64 and took the first element
> >at that address, u64 size. Now after the change, we take
> >first _byte_ of the array, convert it to u64 (adding leading
> >zeros) and compare with a large number.
>
> you are correct, this is obviously wrong, i wonder what i was thinking.
>
> any idea on how to get this right?
> sscanf? union?
I fixed it with:
__u64* buf64;
....
buf64 = (__u64*)buf;
if (buf64[0] != ....).....
NeilBrown
next prev parent reply other threads:[~2010-03-03 4:19 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-02-27 10:14 [mdadm PATCH 0/3] *** fix gcc warnings *** Luca Berra
2010-02-27 13:53 ` [mdadm PATCH 2/3] fix compiler warnings Luca Berra
2010-02-27 13:53 ` [mdadm PATCH 1/3] fix gcc warnings about strict-aliasing rules Luca Berra
2010-03-02 7:40 ` Michael Tokarev
2010-03-02 7:48 ` Luca Berra
2010-03-03 4:19 ` Neil Brown [this message]
2010-02-27 13:53 ` [mdadm PATCH 3/3] workaround unused results Luca Berra
2010-03-02 23:59 ` [mdadm PATCH 0/3] *** fix gcc warnings *** Neil Brown
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100303151957.217fdf0b@notabene.brown \
--to=neilb@suse.de \
--cc=bluca@comedia.it \
--cc=linux-raid@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).