From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Patterson Date: Wed, 29 Sep 2004 20:21:40 +0000 Subject: Re: Segfault fix in scsi_id-0.6 Message-Id: <1096489300.9473.94.camel@bluto.andrew> MIME-Version: 1 Content-Type: multipart/mixed; boundary="=-Nen4P0RiRAEzpfM6M301" List-Id: References: <20040929004539.GA2282@beaverton.ibm.com> In-Reply-To: <20040929004539.GA2282@beaverton.ibm.com> To: linux-hotplug@vger.kernel.org --=-Nen4P0RiRAEzpfM6M301 Content-Type: text/plain Content-Transfer-Encoding: quoted-printable 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: >=20 > > > + serial =3D (char*) (((unaligned_buf - (char *)0) + (ALIGN - 1= )) & > > > ~(ALIGN - 1)); >=20 > 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. >=20 > > But how about just casting to unsigned long instead? Like: >=20 > > + serial =3D (char*) (((unsigned long) unaligned_buf + (ALIGN - 1)) > > + & ~(ALIGN - 1)); >=20 This works on i386 and ia64. As Dave points out, it may not work on architectures where a pointer size !=3D 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 > and use uintptr_t instead. >=20 > -Dave Dodge >=20 --=-Nen4P0RiRAEzpfM6M301 Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.5 (GNU/Linux) iD8DBQBBWxlUoKXgdXvblSgRApwIAJ0ZdixFnHzCjm+rJTNcgMEvDHHlxgCaAqKo ri/AejMzVjAPDj2GAKeq/t4= =r8BY -----END PGP SIGNATURE----- --=-Nen4P0RiRAEzpfM6M301-- ------------------------------------------------------- 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