2022-10-24 05:07:23

by Li kunyu

[permalink] [raw]
Subject: [PATCH 2/2] unicode: mkutf8data: Add malloc allocation check

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

Signed-off-by: Li kunyu <[email protected]>
---
fs/unicode/mkutf8data.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/fs/unicode/mkutf8data.c b/fs/unicode/mkutf8data.c
index e06404a6b106..a929ddf1438c 100644
--- a/fs/unicode/mkutf8data.c
+++ b/fs/unicode/mkutf8data.c
@@ -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;
--
2.18.2


2022-10-24 08:07:31

by Bagas Sanjaya

[permalink] [raw]
Subject: Re: [PATCH 2/2] unicode: mkutf8data: Add malloc allocation check

On Mon, Oct 24, 2022 at 12:51:50PM +0800, Li kunyu wrote:
> Increase the judgment of malloc allocation, and return NULL if the
> condition is met.
>
> Signed-off-by: Li kunyu <[email protected]>
> ---
> fs/unicode/mkutf8data.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/fs/unicode/mkutf8data.c b/fs/unicode/mkutf8data.c
> index e06404a6b106..a929ddf1438c 100644
> --- a/fs/unicode/mkutf8data.c
> +++ b/fs/unicode/mkutf8data.c
> @@ -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.

--
An old man doll... just what I always wanted! - Clara


Attachments:
(No filename) (942.00 B)
signature.asc (235.00 B)
Download all attachments