shithub: scc

Download patch

ref: 88281a76b99c430f41f651baaa6b53eef27fc07e
parent: 7315d856a1485f20691652cc9b2e4165d8095cc4
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Sun Nov 21 13:20:14 EST 2021

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.

--- 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 @@
 		}
 
 		if (cur == freep) {
-			if ((cur = morecore(nunits)) == NULL) {
-				errno = ENOMEM;
+			if ((cur = morecore(nunits)) == NULL)
 				return NULL;
-			}
 		}
 	}
 }