git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [GSoC][RFC] Replace use of atoi() with strtol_i(), as a microproject

From
Mohit Marathe <mohitmarathe@proton.me>
Date
Jan 10, 2024, 17:38 UTC
Message-ID
<F6ejgAfr2IMRNR3Tq0CDTHeT9xMWzJ9ley8M_fnSX97ayRNRp_CEgA62WdtOooi9bha1WJPGB53ptJYQFII2lCbIflwgNvbIaefw7nK8w7M=@proton.me>
In-Reply-To
<CAP8UFD1d7FSa=mUzzUA5e3eSEcCVfaymxWewo5GjdDBi4GyE-g@mail.gmail.com>
Show 19 quoted lines
>In https://public-inbox.org/git/xmqqjzpjsbjl.fsf@gitster.g/ Junio says:
>
>"Some places use atoi() immediately followed by strspn() to skip over
>digits, which means they are parsing an integer and want to continue
>reading after the integer, which is incompatible with what
>strtol_i() wants to do.  They need either a separate helper or an
>updated strtol_i() that optionally allows you to parse the prefix
>and report where the integer ended, e.g., something like:"
>
>and then he suggests the above helper.
>
>So it seems that the two instances you found look like good places
>where Junio says the new helper could be useful.
>
>Now if you want to continue further on this, I think you would need to
>take a closer look at those two instances to see if replacing atoi()
>there with the new helper would improve something there or not. If you
>find it would improve something, be sure to explain what would be
>improved in the commit message.

I took a closer look at `builtin/patch-id.c` and it seems replacing `atoi()` (which is used to parse numbers in the hunk header) wouldn't improve anything, unless I'm missing something.

So then I tried finding other places where `atoi()` can be replaced but I find it difficult to find any reason that would justify the change. So far I've only looked at few of the MANY occurrences of `atoi()`. As far as I understand, the only advantage of `strtol_i()` over `atoi()` is better error handling. And most of places I've seen either already takes care of that or does not need that at all.

Thanks!
Previous: Christian CouderNext: rsbecker@nexbridge.com
Message 3 of 8 in “[GSoC][RFC] Replace use of atoi() with strtol_i(), as a microproject”
  1. mohitmarathe@proton.meJan 8, 2024
  2. Christian CouderJan 9, 2024
  3. Mohit MaratheJan 10, 2024
  4. rsbecker@nexbridge.comJan 10, 2024
  5. Junio C HamanoJan 10, 2024
  6. Junio C HamanoJan 10, 2024
  7. Mohit MaratheJan 12, 2024
  8. Mohit MaratheJan 17, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.