sbrk() does not set errno on overflow
Commit Message
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
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.
@@ -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;