This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: sbrk() does not set errno on overflow
- From: Cyril Hrubis <chrubis at suse dot cz>
- To: Andreas Schwab <schwab at suse dot de>
- Cc: libc-alpha at sourceware dot org
- Date: Tue, 19 May 2015 18:07:20 +0200
- Subject: Re: sbrk() does not set errno on overflow
- Authentication-results: sourceware.org; auth=none
- References: <20150519152646 dot GA2052 at rei dot suse dot de> <mvmvbfobmcm dot fsf at hawking dot suse dot de>
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;
--
Cyril Hrubis
chrubis@suse.cz