delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2003/06/25/14:35:16

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Date: Wed, 25 Jun 2003 18:28:25 +0100
From: Elfyn McBratney <elfyn AT cygwin DOT com>
X-X-Sender: elfyn AT ellixia
Reply-To: cygwin AT cygwin DOT com
To: cygwin AT cygwin DOT com
Subject: Re: assertion "ptr != MAP_FAILED" failed while using mmap
In-Reply-To: <Pine.LNX.4.44.0306251753390.1418-100000@localhost.localdomain>
Message-ID: <Pine.CYG.4.55.0306251825330.3408@ellixia>
References: <Pine DOT LNX DOT 4 DOT 44 DOT 0306251753390 DOT 1418-100000 AT localhost DOT localdomain>
MIME-Version: 1.0

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/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019