From: Andrew Patterson <andrew.patterson@hp.com>
To: linux-hotplug@vger.kernel.org
Subject: Re: Segfault fix in scsi_id-0.6
Date: Wed, 29 Sep 2004 20:21:40 +0000 [thread overview]
Message-ID: <1096489300.9473.94.camel@bluto.andrew> (raw)
In-Reply-To: <20040929004539.GA2282@beaverton.ibm.com>
[-- Attachment #1: Type: text/plain, Size: 1397 bytes --]
On Wed, 2004-09-29 at 15:03 -0400, Dave Dodge wrote:
> On Tue, Sep 28, 2004 at 05:45:39PM -0700, Patrick Mansfield wrote:
> > On Tue, Sep 28, 2004 at 03:33:59PM -0600, Andrew Patterson wrote:
>
> > > + serial = (char*) (((unaligned_buf - (char *)0) + (ALIGN - 1)) &
> > > ~(ALIGN - 1));
>
> Quick comment: the C compiler will treat the (char*)0 as a null
> pointer constant. C makes no guarantee that the resulting value will
> have anything to do with address 0. I believe there are architectures
> where a null pointer has all-bits-on or some other non-zero
> representation, though I don't know if Linux has ever been made to run
> on any of them.
>
> > But how about just casting to unsigned long instead? Like:
>
> > + serial = (char*) (((unsigned long) unaligned_buf + (ALIGN - 1))
> > + & ~(ALIGN - 1));
>
This works on i386 and ia64. As Dave points out, it may not work on
architectures where a pointer size != unsigned long.
Andrew Patterson
> None of this pointer manipulation is technically defined to work, but
> from a practical standpoint this will probably be safe. There's still
> the possibility that an unsigned long can't hold all pointer values.
> If you're willing to rely on a C99 construct, you could include
> <stdint.h> and use uintptr_t instead.
>
> -Dave Dodge
>
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
prev parent reply other threads:[~2004-09-29 20:21 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-09-29 0:45 Segfault fix in scsi_id-0.6 Patrick Mansfield
2004-09-29 18:58 ` Dave Dodge
2004-09-29 20:21 ` Andrew Patterson [this message]
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=1096489300.9473.94.camel@bluto.andrew \
--to=andrew.patterson@hp.com \
--cc=linux-hotplug@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).