sbrk() does not set errno on overflow
diff mbox

Message ID 20150519160719.GB2052@rei.suse.de
State New
Headers show

Commit Message

Cyril Hrubis May 19, 2015, 4:07 p.m. UTC
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:

Comments

Andreas Schwab May 20, 2015, 7:15 a.m. UTC | #1
Cyril Hrubis <chrubis@suse.cz> writes:

> 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;

This looks good, but please also remove the redundant parens.

Andreas.

Patch
diff mbox

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;