* [PATCH v6 2/2] patch-id: replace `atoi()` with `strtoi_with_tail`
2024-02-04 5:48 ` [PATCH v6 " Mohit Marathe via GitGitGadget
@ 2024-02-04 5:48 ` Mohit Marathe via GitGitGadget
0 siblings, 0 replies; 5+ messages in thread
From: Mohit Marathe via GitGitGadget @ 2024-02-04 5:48 UTC (permalink / raw)
To: git; +Cc: Mohit Marathe, Mohit Marathe
From: Mohit Marathe <mohitmarathe23@gmail.com>
The change is made to improve the error-handling capabilities
during the conversion of string to integers. The
`strtoi_with_tail` function offers a more robust mechanism for
converting strings to integers by providing enhanced error
detection. Unlike `atoi`, `strtoi_with_tail` allows the code to
differentiate between a valid conversion and an invalid one,
offering better resilience against potential issues such as
reading hunk header of a corrupted patch.
Signed-off-by: Mohit Marathe <mohitmarathe@proton.me>
---
builtin/patch-id.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/builtin/patch-id.c b/builtin/patch-id.c
index 3894d2b9706..4e9a301e9fb 100644
--- a/builtin/patch-id.c
+++ b/builtin/patch-id.c
@@ -1,3 +1,4 @@
+#include "git-compat-util.h"
#include "builtin.h"
#include "config.h"
#include "diff.h"
@@ -29,14 +30,16 @@ static int scan_hunk_header(const char *p, int *p_before, int *p_after)
{
static const char digits[] = "0123456789";
const char *q, *r;
+ char *endp;
int n;
q = p + 4;
n = strspn(q, digits);
if (q[n] == ',') {
q += n + 1;
- *p_before = atoi(q);
- n = strspn(q, digits);
+ if (strtoi_with_tail(q, 10, p_before, &endp) != 0)
+ return 0;
+ n = endp - q;
} else {
*p_before = 1;
}
@@ -48,8 +51,9 @@ static int scan_hunk_header(const char *p, int *p_before, int *p_after)
n = strspn(r, digits);
if (r[n] == ',') {
r += n + 1;
- *p_after = atoi(r);
- n = strspn(r, digits);
+ if (strtoi_with_tail(r, 10, p_after, &endp) != 0)
+ return 0;
+ n = endp - r;
} else {
*p_after = 1;
}
--
gitgitgadget
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v6 2/2] patch-id: replace `atoi()` with `strtoi_with_tail()`
@ 2024-03-13 15:01 Mohit Marathe
2024-03-14 8:08 ` Junio C Hamano
0 siblings, 1 reply; 5+ messages in thread
From: Mohit Marathe @ 2024-03-13 15:01 UTC (permalink / raw)
To: Mohit Marathe
Cc: Junio C Hamano, Mohit Marathe via GitGitGadget, git,
Mohit Marathe, Christian Couder
Hi,
I am writing to inquire about the status of this patch.
As a contributor, I am curious whether the decision not
to merge this patch was intentional or if it might have been
overlooked. Could you kindly provide some clarity on this matter?
I tried finding this on "What's cooking in Git" but couldn't find it.
If there are any specific reasons for not merging the patch, I would
be grateful if you could share them. Additionally, if there are any
further corrections needed please do let me know.
Thanks,
Mohit
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v6 2/2] patch-id: replace `atoi()` with `strtoi_with_tail()`
2024-03-13 15:01 [PATCH v6 2/2] patch-id: replace `atoi()` with `strtoi_with_tail()` Mohit Marathe
@ 2024-03-14 8:08 ` Junio C Hamano
2024-03-14 10:22 ` Mohit Marathe
0 siblings, 1 reply; 5+ messages in thread
From: Junio C Hamano @ 2024-03-14 8:08 UTC (permalink / raw)
To: Mohit Marathe
Cc: Mohit Marathe via GitGitGadget, git, Mohit Marathe,
Christian Couder
Mohit Marathe <mohitmarathe@proton.me> writes:
> I am writing to inquire about the status of this patch.
Thanks for pinging.
Please be kind to fellow project members by including a URL under
https://lore.kernel.org/git/ to the original discussion. In general
there needs to be a reason why a patch should be applied, but a lack
of reason why a patch should be applied is good enough reason why a
patch may not have been applied so far. I cannot offhand recall
what problems the patch had or if there were additional problems in
the patch that was left unaddressed.
Thanks.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v6 2/2] patch-id: replace `atoi()` with `strtoi_with_tail()`
2024-03-14 8:08 ` Junio C Hamano
@ 2024-03-14 10:22 ` Mohit Marathe
2024-03-18 15:27 ` Junio C Hamano
0 siblings, 1 reply; 5+ messages in thread
From: Mohit Marathe @ 2024-03-14 10:22 UTC (permalink / raw)
To: Junio C Hamano
Cc: Mohit Marathe via GitGitGadget, git, Mohit Marathe,
Christian Couder
> Mohit Marathe mohitmarathe@proton.me writes:
>
> > I am writing to inquire about the status of this patch.
>
>
> Thanks for pinging.
>
> Please be kind to fellow project members by including a URL under
> https://lore.kernel.org/git/ to the original discussion. In general
I thought replying in the same thread as that of patch would be enough.
But now that I think about it, threads can get pretty long. My bad,I
will keep in mind to include the URL of the patch next time.
Just for the record, I was talking about this patch:
https://lore.kernel.org/git/pull.1646.v6.git.1707025718.gitgitgadget
@gmail.com/
> there needs to be a reason why a patch should be applied, but a lack
> of reason why a patch should be applied is good enough reason why a
> patch may not have been applied so far. I cannot offhand recall
> what problems the patch had or if there were additional problems in
> the patch that was left unaddressed.
>
> Thanks.
This makes perfect sense. Thanks for clarifying.
Thanks.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v6 2/2] patch-id: replace `atoi()` with `strtoi_with_tail()`
2024-03-14 10:22 ` Mohit Marathe
@ 2024-03-18 15:27 ` Junio C Hamano
0 siblings, 0 replies; 5+ messages in thread
From: Junio C Hamano @ 2024-03-18 15:27 UTC (permalink / raw)
To: Mohit Marathe
Cc: Mohit Marathe via GitGitGadget, git, Mohit Marathe,
Christian Couder
Mohit Marathe <mohitmarathe@proton.me> writes:
> I thought replying in the same thread as that of patch would be enough.
Well, if you look at the headers of your message, there only is its
own Message-ID and no In-Reply-To or References, which some/many
MUAs go by.
> Just for the record, I was talking about this patch:
> https://lore.kernel.org/git/pull.1646.v6.git.1707025718.gitgitgadget
> @gmail.com/
Yup, thanks. I ended up at the same place with subject search ;-)
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-03-18 15:27 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-13 15:01 [PATCH v6 2/2] patch-id: replace `atoi()` with `strtoi_with_tail()` Mohit Marathe
2024-03-14 8:08 ` Junio C Hamano
2024-03-14 10:22 ` Mohit Marathe
2024-03-18 15:27 ` Junio C Hamano
-- strict thread matches above, loose matches on Subject: below --
2024-01-28 4:42 [PATCH v5 0/2] Replace atoi() with strtoi_with_tail() Mohit Marathe via GitGitGadget
2024-02-04 5:48 ` [PATCH v6 " Mohit Marathe via GitGitGadget
2024-02-04 5:48 ` [PATCH v6 2/2] patch-id: replace `atoi()` with `strtoi_with_tail` Mohit Marathe via GitGitGadget
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 NNTP newsgroup(s).