linux-hotplug.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dave Dodge <dododge@dododge.net>
To: linux-hotplug@vger.kernel.org
Subject: Re: Segfault fix in scsi_id-0.6
Date: Wed, 29 Sep 2004 18:58:04 +0000	[thread overview]
Message-ID: <20040929190347.GA28198@basmati> (raw)
In-Reply-To: <20040929004539.GA2282@beaverton.ibm.com>

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));

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


-------------------------------------------------------
This SF.net email is sponsored by: IT Product Guide on ITManagersJournal
Use IT products in your business? Tell us what you think of them. Give us
Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more
http://productguide.itmanagersjournal.com/guidepromo.tmpl
_______________________________________________
Linux-hotplug-devel mailing list  http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

  reply	other threads:[~2004-09-29 18:58 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 [this message]
2004-09-29 20:21 ` Andrew Patterson

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=20040929190347.GA28198@basmati \
    --to=dododge@dododge.net \
    --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).