From patchwork Tue May 19 16:07:20 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Hrubis X-Patchwork-Id: 6791 Received: (qmail 29782 invoked by alias); 19 May 2015 16:08:00 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 29769 invoked by uid 89); 19 May 2015 16:07:59 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.5 required=5.0 tests=AWL, BAYES_00, KAM_LAZY_DOMAIN_SECURITY, T_RP_MATCHES_RCVD autolearn=no version=3.3.2 X-HELO: mx2.suse.de Date: Tue, 19 May 2015 18:07:20 +0200 From: Cyril Hrubis To: Andreas Schwab Cc: libc-alpha@sourceware.org Subject: Re: sbrk() does not set errno on overflow Message-ID: <20150519160719.GB2052@rei.suse.de> References: <20150519152646.GA2052@rei.suse.de> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) Hi! > You should only set errno if __brk wasn't the reason for the error. Ok. > Also wrong indentation. I suppose I got the curly braces wrong, sorry. What about this one: diff --git a/misc/sbrk.c b/misc/sbrk.c index 87b5472..ecd4397 100644 --- a/misc/sbrk.c +++ b/misc/sbrk.c @@ -49,8 +49,13 @@ __sbrk (intptr_t increment) oldbrk = __curbrk; if ((increment > 0 ? ((uintptr_t) oldbrk + (uintptr_t) increment < (uintptr_t) oldbrk) - : ((uintptr_t) oldbrk < (uintptr_t) -increment)) - || __brk (oldbrk + increment) < 0) + : ((uintptr_t) oldbrk < (uintptr_t) -increment))) + { + __set_errno (ENOMEM); + return (void *) -1; + } + + if (__brk (oldbrk + increment) < 0) return (void *) -1; return oldbrk;