scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit 4e05de3bc5db833754c3b87dacecd190a253649c
parent d84bdd272107e10208c8531b435590d017df410e
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sun, 21 Nov 2021 18:20:14 +0100

libc: Don't trash errno in malloc()

The errno value must be set as near of the error as it happens.
Modyfing the value of errno in a place where the error is not
generated drives to incorrect diagnosis messages.

Diffstat:
Msrc/libc/stdlib/malloc.c | 5+----
1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/src/libc/stdlib/malloc.c b/src/libc/stdlib/malloc.c @@ -1,4 +1,3 @@ -#include <errno.h> #include <stdint.h> #include <stdlib.h> #include <string.h> @@ -153,10 +152,8 @@ malloc(size_t nbytes) } if (cur == freep) { - if ((cur = morecore(nunits)) == NULL) { - errno = ENOMEM; + if ((cur = morecore(nunits)) == NULL) return NULL; - } } } }