This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH] misc/sbrk.c: Set errno to ENOMEM on overflow.
- From: Cyril Hrubis <metan at ucw dot cz>
- To: libc-alpha at sourceware dot org
- Cc: Andreas Schwab <schwab at suse dot de>
- Date: Wed, 20 May 2015 13:50:00 +0200
- Subject: [PATCH] misc/sbrk.c: Set errno to ENOMEM on overflow.
- Authentication-results: sourceware.org; auth=none
---
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