From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: "René Scharfe" <l.s.r@web.de>, git@vger.kernel.org
Subject: [PATCH v2] dropping manual malloc calculations
Date: Thu, 19 Jun 2014 17:16:59 -0400 [thread overview]
Message-ID: <20140619211659.GA32412@sigill.intra.peff.net> (raw)
In-Reply-To: <xmqq38f0j13u.fsf@gitster.dls.corp.google.com>
On Thu, Jun 19, 2014 at 09:49:41AM -0700, Junio C Hamano wrote:
> If we twist the logic behind the 'mkpathdup' name a little bit,
> perhaps we can call it sprintf_dup or something. That is, "sprintf
> wants a fixed preallocated piece of memory to print into, and we
> relieve the callers of having to do so", perhaps?
Right, that is the "dup" I was thinking of. Anyway, I think René's
"xstrfmt" is my favorite of the suggestions, and you seemed to like it,
too. Here is a re-roll using that name.
The first two patches are the same except for the name change. The rest
are more applications of it (and other techniques) found by grepping for
"malloc.*strlen". The diffstat is very encouraging, and I think the
results are much more readable (in addition to being more obviously
correct). The last two also fix real "bugs", but I doubt either is a
problem in practice.
builtin/apply.c | 4 +--
builtin/fetch.c | 9 ++----
builtin/fmt-merge-msg.c | 7 ++---
builtin/name-rev.c | 5 +---
builtin/receive-pack.c | 5 +---
builtin/show-branch.c | 10 +++----
environment.c | 12 +++-----
http-push.c | 24 +++++-----------
http-walker.c | 6 ++--
match-trees.c | 9 ++----
merge-recursive.c | 53 ++++++++++++++++++++---------------
merge.c | 42 +++++++++------------------
remote.c | 6 +---
sequencer.c | 9 ++----
sha1_name.c | 5 +---
shell.c | 6 +---
strbuf.c | 19 +++++++++++++
strbuf.h | 9 ++++++
unpack-trees.c | 17 ++++-------
walker.c | 18 ++++++------
20 files changed, 117 insertions(+), 158 deletions(-)
[01/10]: strbuf: add xstrfmt helper
[02/10]: use xstrfmt in favor of manual size calculations
[03/10]: use xstrdup instead of xmalloc + strcpy
[04/10]: use xstrfmt to replace xmalloc + sprintf
[05/10]: use xstrfmt to replace xmalloc + strcpy/strcat
[06/10]: setup_git_env: use git_pathdup instead of xmalloc + sprintf
[07/10]: sequencer: use argv_array_pushf
[08/10]: merge: use argv_array when spawning merge strategy
[09/10]: walker_fetch: fix minor memory leak
[10/10]: unique_path: fix unlikely heap overflow
next prev parent reply other threads:[~2014-06-19 21:17 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-18 20:00 [PATCH 0/2] dropping manual malloc calculations Jeff King
2014-06-18 20:01 ` [PATCH 1/2] strbuf: add xstrdup_fmt helper Jeff King
2014-06-18 22:32 ` Junio C Hamano
2014-06-19 9:05 ` Jeff King
2014-06-19 16:49 ` Junio C Hamano
2014-06-19 21:16 ` Jeff King [this message]
2014-06-19 21:18 ` [PATCH v2 01/10] strbuf: add xstrfmt helper Jeff King
2014-06-19 21:19 ` [PATCH v2 02/10] use xstrfmt in favor of manual size calculations Jeff King
2014-06-19 21:19 ` [PATCH v2 03/10] use xstrdup instead of xmalloc + strcpy Jeff King
2014-06-19 21:24 ` [PATCH v2 04/10] use xstrfmt to replace xmalloc + sprintf Jeff King
2014-06-19 21:26 ` [PATCH v2 05/10] use xstrfmt to replace xmalloc + strcpy/strcat Jeff King
2014-06-19 21:28 ` [PATCH v2 06/10] setup_git_env: use git_pathdup instead of xmalloc + sprintf Jeff King
2014-06-23 10:21 ` Eric Sunshine
2014-06-23 22:43 ` Junio C Hamano
2014-06-24 13:02 ` Duy Nguyen
2014-06-24 13:30 ` Duy Nguyen
2014-06-24 20:58 ` Jeff King
2014-06-25 12:37 ` Duy Nguyen
2014-06-25 17:20 ` Junio C Hamano
2014-06-25 17:22 ` Jeff King
2014-06-25 19:54 ` Junio C Hamano
2014-06-19 21:28 ` [PATCH v2 07/10] sequencer: use argv_array_pushf Jeff King
2014-06-19 21:29 ` [PATCH v2 08/10] merge: use argv_array when spawning merge strategy Jeff King
2014-06-19 21:29 ` [PATCH v2 09/10] walker_fetch: fix minor memory leak Jeff King
2014-06-19 21:30 ` [PATCH v2 10/10] unique_path: fix unlikely heap overflow Jeff King
2014-06-19 16:52 ` [PATCH 1/2] strbuf: add xstrdup_fmt helper René Scharfe
2014-06-18 20:02 ` [PATCH 2/2] use xstrdup_fmt in favor of manual size calculations Jeff King
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20140619211659.GA32412@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=l.s.r@web.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).