* [PATCH] builtin: submodule--helper: Add allocation check of module_cb structure objects may be helpful in case of allocation failure
@ 2022-11-22 3:17 Li kunyu
2022-11-22 4:22 ` Junio C Hamano
2022-11-22 8:08 ` Bagas Sanjaya
0 siblings, 2 replies; 3+ messages in thread
From: Li kunyu @ 2022-11-22 3:17 UTC (permalink / raw)
To: git; +Cc: Li kunyu
The purpose of using temp is unknown, but adding an allocation failure
report should be helpful.
Signed-off-by: Li kunyu <kunyu@nfschina.com>
---
builtin/submodule--helper.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index b63f420ece..2e379623ea 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -1077,6 +1077,9 @@ static void submodule_summary_callback(struct diff_queue_struct *q,
if (!S_ISGITLINK(p->one->mode) && !S_ISGITLINK(p->two->mode))
continue;
temp = (struct module_cb*)malloc(sizeof(struct module_cb));
+ if (!temp)
+ BUG("The module_cb structure object fails to be allocated and the program may terminate abnormally");
+
temp->mod_src = p->one->mode;
temp->mod_dst = p->two->mode;
temp->oid_src = p->one->oid;
--
2.18.2
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] builtin: submodule--helper: Add allocation check of module_cb structure objects may be helpful in case of allocation failure
2022-11-22 3:17 [PATCH] builtin: submodule--helper: Add allocation check of module_cb structure objects may be helpful in case of allocation failure Li kunyu
@ 2022-11-22 4:22 ` Junio C Hamano
2022-11-22 8:08 ` Bagas Sanjaya
1 sibling, 0 replies; 3+ messages in thread
From: Junio C Hamano @ 2022-11-22 4:22 UTC (permalink / raw)
To: Li kunyu; +Cc: git
Li kunyu <kunyu@nfschina.com> writes:
> The purpose of using temp is unknown, but adding an allocation failure
> report should be helpful.
Yuck. Use of xmalloc() may be more appropriate.
Use of BUG() in a context like this is never the right thing to do.
BUG() is reserved for cases where the condition should NEVER hold
true in a correctly written program, and even for a correctly
written program, malloc() can fail after you allocated too much
memory from the heap.
>
> Signed-off-by: Li kunyu <kunyu@nfschina.com>
> ---
> builtin/submodule--helper.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
> index b63f420ece..2e379623ea 100644
> --- a/builtin/submodule--helper.c
> +++ b/builtin/submodule--helper.c
> @@ -1077,6 +1077,9 @@ static void submodule_summary_callback(struct diff_queue_struct *q,
> if (!S_ISGITLINK(p->one->mode) && !S_ISGITLINK(p->two->mode))
> continue;
> temp = (struct module_cb*)malloc(sizeof(struct module_cb));
> + if (!temp)
> + BUG("The module_cb structure object fails to be allocated and the program may terminate abnormally");
> +
> temp->mod_src = p->one->mode;
> temp->mod_dst = p->two->mode;
> temp->oid_src = p->one->oid;
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] builtin: submodule--helper: Add allocation check of module_cb structure objects may be helpful in case of allocation failure
2022-11-22 3:17 [PATCH] builtin: submodule--helper: Add allocation check of module_cb structure objects may be helpful in case of allocation failure Li kunyu
2022-11-22 4:22 ` Junio C Hamano
@ 2022-11-22 8:08 ` Bagas Sanjaya
1 sibling, 0 replies; 3+ messages in thread
From: Bagas Sanjaya @ 2022-11-22 8:08 UTC (permalink / raw)
To: Li kunyu, git
On 11/22/22 10:17, Li kunyu wrote:
> The purpose of using temp is unknown, but adding an allocation failure
> report should be helpful.
>
Don't you understand the code?
> Signed-off-by: Li kunyu <kunyu@nfschina.com>
> ---
> builtin/submodule--helper.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
> index b63f420ece..2e379623ea 100644
> --- a/builtin/submodule--helper.c
> +++ b/builtin/submodule--helper.c
> @@ -1077,6 +1077,9 @@ static void submodule_summary_callback(struct diff_queue_struct *q,
> if (!S_ISGITLINK(p->one->mode) && !S_ISGITLINK(p->two->mode))
> continue;
> temp = (struct module_cb*)malloc(sizeof(struct module_cb));
> + if (!temp)
> + BUG("The module_cb structure object fails to be allocated and the program may terminate abnormally");
> +
Why do you check whenever allocating temp is successful?
--
An old man doll... just what I always wanted! - Clara
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-11-22 8:10 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-22 3:17 [PATCH] builtin: submodule--helper: Add allocation check of module_cb structure objects may be helpful in case of allocation failure Li kunyu
2022-11-22 4:22 ` Junio C Hamano
2022-11-22 8:08 ` Bagas Sanjaya
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).