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

Re: [PATCH v10] git: use calloc instead of malloc + memset where possible

From
Junio C Hamano <gitster@pobox.com>
Date
Dec 18, 2024, 15:39 UTC
Message-ID
<xmqqr065t2yp.fsf@gitster.g>
In-Reply-To
<pull.1390.v10.git.git.1734485187081.gitgitgadget@gmail.com>
"AreaZR via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 5 quoted lines
> From: Seija Kijin <doremylover123@gmail.com>
>
> Avoid calling malloc + memset by calling calloc.
>
> Signed-off-by: Seija <doremylover123@gmail.com>
Name mismatch.
>  remote.c    |  4 ++--
>  submodule.c | 10 +++++-----
>  2 files changed, 7 insertions(+), 7 deletions(-)

I somehow hoped to see that this shrinks the line count, as you are essentially replacing two calls (malloc + memset) with one, but that is not what is happening, which is a bit disapointing.

But this is a strict improvement, I guess. The reader needs to be familiar with the CALLOC_ARRAY() macro to understand it, which may make the code less newbie-friendly (as opposed to malloc+memset any reasonably competent C programmer would understand without any prior knowledge of the conventions used by this project).

Previous: AreaZR via GitGitGadgetNext: AreaZR via GitGitGadget
Message 15 of 16 in “maintenance: use xcalloc instead of xmalloc where possible”
  1. maintenance: use xcalloc instead of xmalloc where possibleRose via GitGitGadget, Dec 5, 2022
  2. Jeff HostetlerDec 5, 2022
  3. maintenance: use xcalloc instead of xmalloc where possibleRose via GitGitGadget, Dec 5, 2022
  4. maintenance: use xcalloc instead of xmalloc where possibleRose via GitGitGadget, Dec 5, 2022
  5. maintenance: use calloc instead of malloc where possibleRose via GitGitGadget, Dec 5, 2022
  6. Junio C HamanoDec 6, 2022
  7. revision: use calloc instead of malloc where possibleRose via GitGitGadget, Dec 6, 2022
  8. Ævar Arnfjörð BjarmasonDec 6, 2022
  9. revision: use calloc instead of malloc where possibleRose via GitGitGadget, Dec 6, 2022
  10. Bagas SanjayaDec 7, 2022
  11. revision: use calloc instead of malloc where possibleAreaZR via GitGitGadget, Dec 18, 2024
  12. git: use calloc instead of malloc where possibleAreaZR via GitGitGadget, Dec 18, 2024
  13. git: use calloc instead of malloc where possibleAreaZR via GitGitGadget, Dec 18, 2024
  14. git: use calloc instead of malloc + memset where possibleAreaZR via GitGitGadget, Dec 18, 2024
  15. Junio C HamanoDec 18, 2024
  16. git: use calloc instead of malloc + memset where possibleAreaZR via GitGitGadget, Dec 18, 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.