9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: "Douglas A. Gwyn" <DAGwyn@null.net>
To: 9fans@cse.psu.edu
Subject: Re: [9fans] plan9port build failure on Linux (debian)
Date: Wed,  5 Mar 2008 16:21:49 +0000	[thread overview]
Message-ID: <47CEC68A.3A62779D@null.net> (raw)
In-Reply-To: <20080304044330.C6B7D1E8C55@holo.morphisms.net>

Russ Cox wrote:
> The test for wraparound when computing len in sprint looks like:
>         len = 1<<30;  /* big number, but sprint is deprecated anyway */
>         /*
>          * on PowerPC, the stack is near the top of memory, so
>          * we must be sure not to overflow a 32-bit pointer.
>          */
>         if(buf+len < buf)
>                 len = -(uintptr)buf-1;

There are several serious portability issues with that.
The main thing is that casting a pointer to an integer type
does not in general produce a "byte address", but rather
just some encoding that can be converted back to a pointer.

And of course buf+len produces undefined behavior if buf
does not point to an array of length at least len.

Such an address-range check chould be delegated to an
auxiliary function that is tailored to the platform as
part of the porting process.  That way whatever nonportable
kludge is used won't silently find its way into a port
where it doesn't work.


  reply	other threads:[~2008-03-05 16:21 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-03  4:20 David Morris
2008-03-03  5:23 ` Hongzheng Wang
     [not found]   ` <20080303084557.GA24732@morris-clan.net>
2008-03-03  8:46     ` David Morris
2008-03-03 15:09       ` sqweek
2008-03-03 16:25         ` David Morris
2008-03-03 16:17 ` Russ Cox
2008-03-03 17:27   ` David Morris
2008-03-03 19:02     ` erik quanstrom
     [not found]       ` <20080303195459.GE28226@morris-clan.net>
2008-03-03 19:56         ` David Morris
2008-03-04  4:42   ` Russ Cox
2008-03-05 16:21     ` Douglas A. Gwyn [this message]
2008-03-03 14:10 erik quanstrom

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=47CEC68A.3A62779D@null.net \
    --to=dagwyn@null.net \
    --cc=9fans@cse.psu.edu \
    /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).