[PATCH] misc/sbrk.c: Set errno to ENOMEM on overflow.

Cyril Hrubis metan@ucw.cz
Wed May 20 14:11:00 GMT 2015


---
 ChangeLog   |  4 ++++
 misc/sbrk.c | 13 +++++++++----
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index c1a73c8..252af8e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2015-05-20  Cyril Hrubis <chrubis@suse.cz>
+
+	* misc/sbrk.c: Set errno to ENOMEM on overflow.
+
 2015-05-19  Joseph Myers  <joseph@codesourcery.com>
 
 	[BZ #18244]
diff --git a/misc/sbrk.c b/misc/sbrk.c
index 87b5472..89ab9c4 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;
-- 
2.0.5


-- 
Cyril Hrubis
chrubis@suse.cz



More information about the Libc-alpha mailing list