From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31056 invoked by alias); 26 Jun 2003 05:47:21 -0000 Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com Received: (qmail 1331 invoked from network); 26 Jun 2003 05:32:36 -0000 Received: from unknown (HELO main.gmane.org) (80.91.224.249) by sources.redhat.com with SMTP; 26 Jun 2003 05:32:36 -0000 Received: from list by main.gmane.org with local (Exim 3.35 #1 (Debian)) id 19VPMm-0004mp-00 for ; Thu, 26 Jun 2003 07:32:16 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: cygwin@cygwin.com Received: from news by main.gmane.org with local (Exim 3.35 #1 (Debian)) id 19VPMm-0004me-00 for ; Thu, 26 Jun 2003 07:32:16 +0200 From: "Alex Vinokur" Subject: Re: assertion "ptr != MAP_FAILED" failed while using mmap Date: Thu, 26 Jun 2003 08:31:00 -0000 Message-ID: References: X-Complaints-To: usenet@main.gmane.org X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200 X-SW-Source: 2003-06/txt/msg01203.txt.bz2 "Alex Vinokur" wrote in message news:bddr4g$on$1@main.gmane.org... > > "Igor Pechtchanski" wrote in message news:Pine.GSO.4.44.0306251849140.22307-100000@slinky.cs.nyu.edu... > [snip] > > > > Umm, Elfyn, the semantics of "assert()" is that you assert some predicate > > to be true. If the predicate is indeed true, the program continues > > normally. If the predicate is false, the program fails. > > The predicate in this case is "ptr != MAP_FAILED". Thus, the predicate > > was false when the assertion failed, and ptr == MAP_FAILED. > > > > To the OP: this means that mmap() did fail for some reason. It should > > have set errno to indicate why. You should check that instead of > > asserting -- mmap does fail occasionally. Also FYI, once you assert, the > > following test for "ptr != MAP_FAILED" is redundant -- the program will > > not get there otherwise. > > Igor > [snip] > > > Here is updated 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); errno = 0; > char* ptr = (char*)mmap(0, sz, PROT_READ, 0, fd, 0); > -------------------------------- Must be removed > errno = 0; -------------------------------- > if (ptr != MAP_FAILED) > { > string str(ptr, ptr+sz); > munmap(ptr, sz); > } > else > { > assert (ptr == MAP_FAILED); > printf ("=== Error : %u %s ===\n", errno, strerror (errno)); > } > assert (ptr != MAP_FAILED); // Here assertion failed > > close(fd); > } > -------------------------------------- > > The program prints: === Error : 22 Invalid argument === Which argument? [snip] ========================================== Alex Vinokur mailto:alexvn@connect.to http://www.simtel.net/pub/oth/19088.html http://sourceforge.net/users/alexvn ========================================== -- 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/