Skip to contentSkip to conversation

boot: simple_alloc: check after increasing memory allocation

PATCH Applied Li zeming 3 participants 3 messages Dec 19, 2022 – Mar 13, 2024 PowerPC

lore
Share & tools
lore

Li zeming

author
#0 lore raw

PATCH 1/1 boot: simple_alloc: check after increasing memory allocation

The pointer new adds judgment and should help with program robustness.

---
 arch/powerpc/boot/simple_alloc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
arch/powerpc/boot/simple_alloc.c +3 -1
index 267d6524caac..db9aaa5face3 100644
@@ -112,7 +112,9 @@ static void *simple_realloc(void *ptr, unsigned long size)
 		return ptr;
 
 	new = simple_malloc(size);
-	memcpy(new, ptr, p->size);
+	if (new)
+		memcpy(new, ptr, p->size);
+
 	simple_free(ptr);
 	return new;
 }
Signature · 1 line
2.18.2
#1 lore raw

Le 19/12/2022 à 03:18, Li zeming a écrit :

Quoted 1 line

The pointer new adds judgment and should help with program robustness.

This text is not understandable.

Do you mean:

simple_malloc() will return NULL when there is now enough memory left. Check pointer 'new' before using it to copy the old data.

Quoted 21 lines
---
  arch/powerpc/boot/simple_alloc.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
arch/powerpc/boot/simple_alloc.c +3 -1
index 267d6524caac..db9aaa5face3 100644
@@ -112,7 +112,9 @@ static void *simple_realloc(void *ptr, unsigned long size)
  		return ptr;
 
  	new = simple_malloc(size);
-	memcpy(new, ptr, p->size);
+	if (new)
+		memcpy(new, ptr, p->size);
+
  	simple_free(ptr);
  	return new;
  }