Skip to contentSkip to conversation

unicode: mkutf8data: Add malloc allocation check

PATCH In review Li kunyu 2 participants 2 messages Oct 24, 2022

Subsystems (2)
lore
Share & tools
lore

Li kunyu

author
#0 lore raw

PATCH 2/2 unicode: mkutf8data: Add malloc allocation check

Increase the judgment of malloc allocation, and return NULL if the condition is met.

---
 fs/unicode/mkutf8data.c | 3 +++
 1 file changed, 3 insertions(+)
fs/unicode/mkutf8data.c +3 -0
index e06404a6b106..a929ddf1438c 100644
@@ -495,6 +495,9 @@ static struct node *alloc_node(struct node *parent)
 	int bitnum;
 
 	node = malloc(sizeof(*node));
+	if (!node)
+		return NULL;
+
 	node->left = node->right = NULL;
 	node->parent = parent;
 	node->leftnode = NODE;
Signature · 1 line
2.18.2
#1 lore raw
Quoted 13 lines · Li kunyu

Increase the judgment of malloc allocation, and return NULL if the condition is met.

---
 fs/unicode/mkutf8data.c | 3 +++
 1 file changed, 3 insertions(+)
fs/unicode/mkutf8data.c +0 -0
index e06404a6b106..a929ddf1438c 100644

fs/unicode/mkutf8data.c static struct node *alloc_node(struct node *parent) · line 503

Quoted 9 lines
fs/unicode/mkutf8data.c +3 -0
@@ -495,6 +495,9 @@ static struct node *alloc_node(struct node *parent)
 	int bitnum;
 
 	node = malloc(sizeof(*node));
+	if (!node)
+		return NULL;
+
 	node->left = node->right = NULL;
 	node->parent = parent;
 	node->leftnode = NODE;

What?

This is not "malloc judgement", but rather return NULL if node fails to allocate.

Please, please reword the patch description.

Thanks.

Signature · 1 line
An old man doll... just what I always wanted! - Clara