about summary refs log tree commit diff
path: root/misc/sbrk.c
diff options
context:
space:
mode:
Diffstat (limited to 'misc/sbrk.c')
-rw-r--r--misc/sbrk.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/misc/sbrk.c b/misc/sbrk.c
index 87b5472bda..89ab9c4a8c 100644
--- a/misc/sbrk.c
+++ b/misc/sbrk.c
@@ -47,10 +47,15 @@ __sbrk (intptr_t increment)
     return __curbrk;
 
   oldbrk = __curbrk;
-  if ((increment > 0
-       ? ((uintptr_t) oldbrk + (uintptr_t) increment < (uintptr_t) oldbrk)
-       : ((uintptr_t) oldbrk < (uintptr_t) -increment))
-      || __brk (oldbrk + increment) < 0)
+  if (increment > 0
+      ? ((uintptr_t) oldbrk + (uintptr_t) increment < (uintptr_t) oldbrk)
+      : ((uintptr_t) oldbrk < (uintptr_t) -increment))
+    {
+      __set_errno (ENOMEM);
+      return (void *) -1;
+    }
+
+  if (__brk (oldbrk + increment) < 0)
     return (void *) -1;
 
   return oldbrk;