public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Elfyn McBratney <elfyn@cygwin.com>
To: cygwin@cygwin.com
Subject: Re: assertion "ptr != MAP_FAILED" failed while using mmap
Date: Wed, 25 Jun 2003 21:40:00 -0000	[thread overview]
Message-ID: <Pine.CYG.4.55.0306251825330.3408@ellixia> (raw)
In-Reply-To: <Pine.LNX.4.44.0306251753390.1418-100000@localhost.localdomain>

On Wed, 25 Jun 2003, Ronald Landheer-Cieslak wrote:

> On Wed, 25 Jun 2003, Elfyn McBratney wrote:
>
> > On Wed, 25 Jun 2003, Alex Vinokur wrote:
> >
> > > ===========================================
> > > Windows 2000
> > > CYGWIN_NT-5.0 1.3.22(0.78/3/2)
> > > GNU gcc version 3.2 20020927 (prerelease)
> > > ===========================================
> > >
> > > Here is some function.
> > >
> > > --------------------------------------
> > > void read_file (char* filename_i)
> > > {
> > > int fd = open(filename_i, O_RDONLY);
> > >   assert (fd > 2);
> > >
> > > off_t sz = lseek(fd, 0, SEEK_END);
> > > char* ptr = (char*)mmap(0, sz, PROT_READ, 0, fd, 0);
> > >
> > >   assert (ptr != MAP_FAILED);  // Here assertion failed
> > >   if (ptr != MAP_FAILED)
> > >   {
> > >     string str(ptr, ptr+sz);
> > >     munmap(ptr, sz);
> > >   }
> > >
> > >   close(fd);
> > > }
> > > --------------------------------------
> > >
> > > Assertion  "ptr != MAP_FAILED)" failed.
> > > What might cause that?
> >
> > This is just a stab in the dark, of course, but surely `ptr != MAP_FAILED'
> > would indicate that the mmap did not fail? Assertions (assert()) are based on
> > true or false, so the above assert is false in that `ptr != MAP_FAILED'.
> >
> > Elfyn
> >
> >
> Ehm..
>
> If ptr != MAP_FAILED is not true, that means ptr == MAP_FAILED.
> assert(ptr != MAP_FAILED) thus fails if mmap fails..
>
> unless I'm missing something..

But what's the point in 'assert (ptr != NULL)'? Surely the best way to test for
failure is the other way round (s/!=/==/), if ptr == MAP_FAILED assert, or
continue...No?

Elfyn
-- 


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

  reply	other threads:[~2003-06-25 18:30 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-06-25 15:17 Alex Vinokur
2003-06-25 16:51 ` Elfyn McBratney
2003-06-25 16:55   ` Ronald Landheer-Cieslak
2003-06-25 21:40     ` Elfyn McBratney [this message]
2003-06-26  5:06       ` Igor Pechtchanski
2003-06-26  6:08         ` Alex Vinokur
2003-06-26  8:31           ` Alex Vinokur
2003-06-26  9:53             ` Brian Dessent
2003-06-26 11:33               ` Alex Vinokur
2003-06-26  9:23           ` Brian Dessent
2003-06-26 19:21 ` Comparative performance : Reading contents from file into one string Alex Vinokur

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=Pine.CYG.4.55.0306251825330.3408@ellixia \
    --to=elfyn@cygwin.com \
    --cc=cygwin@cygwin.com \
    /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 read-only IMAP folder(s) and NNTP newsgroup(s).