This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: sbrk() does not set errno on overflow


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]