From: Andrew Morton <akpm@linux-foundation.org>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Gerd Hoffmann <kraxel@redhat.com>,
arnd@arndb.de, "H. Peter Anvin" <hpa@zytor.com>,
linux-api@vger.kernel.org, linux-arch@vger.kernel.org,
Ingo Molnar <mingo@elte.hu>,
ralf@linux-mips.org, tglx@linutronix.de,
Al Viro <viro@zeniv.linux.org.uk>
Subject: Re: [patch 143/166] preadv/pwritev: Add preadv and pwritev system calls.
Date: Sat, 4 Apr 2009 10:38:30 -0700 [thread overview]
Message-ID: <20090404103830.56f66e13.akpm@linux-foundation.org> (raw)
In-Reply-To: <alpine.LFD.2.00.0904030739540.4130@localhost.localdomain>
On Fri, 3 Apr 2009 08:03:22 -0700 (PDT) Linus Torvalds <torvalds@linux-foundation.org> wrote:
> +static inline loff_t pos_from_hilo(unsigned long high, unsigned long low)
> +{
> +#define HALF_LONG_BITS (BITS_PER_LONG / 2)
> + return ((high << HALF_LONG_BITS) << HALF_LONG_BITS) | low;
> +}
Does C promote the `unsigned long high' beforehand, or will the
intermediate expression overflow?
<does it the old-fashioned way>
y:/home/akpm> cat t.c
#define HALF_LONG_BITS 16
main()
{
unsigned hi = 0x43;
unsigned lo = 0x42;
unsigned long long res;
res = ((hi << 16) << 16) | lo;
printf("%llx\n", res);
}
y:/home/akpm> gcc -O t.c
y:/home/akpm> ./a.out
42
I think it's wrong on 32-bit?
Also, HALF_LONG_BITS is 32 on 64-bit, so "high" gets shifted to zero.
It's unclear whether this was deliberate, but either way, it's a sneaky
trick and deserves a code comment!
next prev parent reply other threads:[~2009-04-04 17:38 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-04-02 23:59 [patch 143/166] preadv/pwritev: Add preadv and pwritev system calls akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b
2009-04-02 23:59 ` akpm
[not found] ` <200904022359.n32NxNYu022834-AB4EexQrvXRQetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org>
2009-04-03 1:43 ` Linus Torvalds
2009-04-03 1:43 ` Linus Torvalds
2009-04-03 8:35 ` Gerd Hoffmann
2009-04-03 9:25 ` Gerd Hoffmann
2009-04-03 9:25 ` Gerd Hoffmann
[not found] ` <49D5D609.7030400-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2009-04-03 11:53 ` Gerd Hoffmann
2009-04-03 11:53 ` Gerd Hoffmann
2009-04-03 11:53 ` Gerd Hoffmann
2009-04-03 15:03 ` Linus Torvalds
2009-04-03 19:57 ` Gerd Hoffmann
[not found] ` <49D66A22.7090909-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2009-04-03 20:08 ` Linus Torvalds
2009-04-03 20:08 ` Linus Torvalds
2009-04-04 17:38 ` Andrew Morton [this message]
2009-04-04 17:51 ` Linus Torvalds
[not found] ` <alpine.LFD.2.00.0904021839390.15441-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2009-04-03 16:57 ` H. Peter Anvin
2009-04-03 16:57 ` H. Peter Anvin
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=20090404103830.56f66e13.akpm@linux-foundation.org \
--to=akpm@linux-foundation.org \
--cc=arnd@arndb.de \
--cc=hpa@zytor.com \
--cc=kraxel@redhat.com \
--cc=linux-api@vger.kernel.org \
--cc=linux-arch@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=ralf@linux-mips.org \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
--cc=viro@zeniv.linux.org.uk \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.