sbrk() does not set errno on overflow
Cyril Hrubis
chrubis@suse.cz
Tue May 19 18:05:00 GMT 2015
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
More information about the Libc-alpha
mailing list