From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/7 Path: news.gmane.org!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: linux/sbrk is wrong Date: Sun, 22 May 2011 12:09:14 -0400 Message-ID: <20110522160914.GR277@brightrain.aerifal.cx> References: <20110522145555.GE6142@port70.net> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1306081160 7280 80.91.229.12 (22 May 2011 16:19:20 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sun, 22 May 2011 16:19:20 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-90-gllmg-musl=m.gmane.org@lists.openwall.com Sun May 22 18:19:17 2011 Return-path: Envelope-to: gllmg-musl@lo.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by lo.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1QOBN6-0003y1-Vc for gllmg-musl@lo.gmane.org; Sun, 22 May 2011 18:19:17 +0200 Original-Received: (qmail 24228 invoked by uid 550); 22 May 2011 16:19:16 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 24215 invoked from network); 22 May 2011 16:19:16 -0000 Content-Disposition: inline In-Reply-To: <20110522145555.GE6142@port70.net> User-Agent: Mutt/1.5.21 (2010-09-15) Xref: news.gmane.org gmane.linux.lib.musl.general:7 Archived-At: On Sun, May 22, 2011 at 04:55:55PM +0200, Szabolcs Nagy wrote: > linux brk syscall returns the end pointer > so if it fails then the old one > if it succeeds then the new one > > the current implementation of sbrk returns > the end of the allocated area instead of > the begining IMO there's no way for correct code to use these functions anyway, but I'll fix them anyway. > int brk(void *end) > { > - return -(syscall(SYS_brk, end) == -1); > + return -((void *)syscall(SYS_brk, end) != end); > } This looks fine. > void *sbrk(ptrdiff_t inc) > { > - return (void *)syscall(SYS_brk, syscall(SYS_brk, 0)+inc); > + void *p = (void *)syscall(SYS_brk, 0); > + > + if (inc == 0) > + return p; > + if ((void *)syscall(SYS_brk, p+inc) == p+inc) This line is invalid C. p+inc is not defined since p has type void *. The most correct would probably be to use uintptr_t internally everywhere and just cast to void * in the return statement. Rich