1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-06-01 15:56:08 +02:00
git/builtin
Jeff King 00b6c178c3 use strbuf_complete to conditionally append slash
When working with paths in strbufs, we frequently want to
ensure that a directory contains a trailing slash before
appending to it. We can shorten this code (and make the
intent more obvious) by calling strbuf_complete.

Most of these cases are trivially identical conversions, but
there are two things to note:

  - in a few cases we did not check that the strbuf is
    non-empty (which would lead to an out-of-bounds memory
    access). These were generally not triggerable in
    practice, either from earlier assertions, or typically
    because we would have just fed the strbuf to opendir(),
    which would choke on an empty path.

  - in a few cases we indexed the buffer with "original_len"
    or similar, rather than the current sb->len, and it is
    not immediately obvious from the diff that they are the
    same. In all of these cases, I manually verified that
    the strbuf does not change between the assignment and
    the strbuf_complete call.

This does not convert cases which look like:

  if (sb->len && !is_dir_sep(sb->buf[sb->len - 1]))
	  strbuf_addch(sb, '/');

as those are obviously semantically different. Some of these
cases arguably should be doing that, but that is out of
scope for this change, which aims purely for cleanup with no
behavior change (and at least it will make such sites easier
to find and examine in the future, as we can grep for
strbuf_complete).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-10-05 11:08:06 -07:00
..
add.c Merge branch 'sb/remove-unused-var-from-builtin-add' into maint 2015-08-19 14:41:33 -07:00
am.c Merge branch 'jc/builtin-am-signoff-regression-fix' 2015-09-08 15:35:05 -07:00
annotate.c
apply.c apply: convert root string to strbuf 2015-10-05 11:08:04 -07:00
archive.c
bisect--helper.c
blame.c avoid sprintf and strcpy with flex arrays 2015-10-05 11:08:05 -07:00
branch.c write_file(): drop "fatal" parameter 2015-08-24 13:09:02 -07:00
bundle.c
cat-file.c
check-attr.c
check-ignore.c
check-mailmap.c
check-ref-format.c
checkout-index.c
checkout.c Merge branch 'jc/calloc-pathspec' into maint 2015-09-03 19:18:00 -07:00
clean.c use strbuf_complete to conditionally append slash 2015-10-05 11:08:06 -07:00
clone.c Merge branch 'jk/guess-repo-name-regression-fix' into maint 2015-08-25 16:09:17 -07:00
column.c
commit-tree.c
commit.c Merge branch 'dt/commit-preserve-base-index-upon-opportunistic-cache-tree-update' 2015-09-01 16:31:29 -07:00
config.c config: use xstrfmt in normalize_value 2015-09-25 10:18:18 -07:00
count-objects.c
credential.c
describe.c Merge branch 'sg/describe-contains' 2015-08-31 15:39:10 -07:00
diff-files.c
diff-index.c
diff-tree.c
diff.c
fast-export.c
fetch-pack.c
fetch.c use alloc_ref rather than hand-allocating "struct ref" 2015-10-05 11:08:05 -07:00
fmt-merge-msg.c
for-each-ref.c
fsck.c fsck: use for_each_loose_file_in_objdir 2015-10-05 11:08:06 -07:00
gc.c convert trivial sprintf / strcpy calls to xsnprintf 2015-09-25 10:18:18 -07:00
get-tar-commit-id.c
grep.c
hash-object.c
help.c convert strncpy to memcpy 2015-10-05 11:08:06 -07:00
index-pack.c use xsnprintf for generating git object headers 2015-09-25 10:18:18 -07:00
init-db.c init: use strbufs to store paths 2015-10-05 11:07:04 -07:00
interpret-trailers.c
log.c use strbuf_complete to conditionally append slash 2015-10-05 11:08:06 -07:00
ls-files.c ps_matched: xcalloc() takes nmemb and then element size 2015-08-20 09:57:38 -07:00
ls-remote.c replace trivial malloc + sprintf / strcpy calls with xstrfmt 2015-09-25 10:18:18 -07:00
ls-tree.c convert trivial sprintf / strcpy calls to xsnprintf 2015-09-25 10:18:18 -07:00
mailinfo.c
mailsplit.c mailsplit: make PATH_MAX buffers dynamic 2015-09-25 10:18:18 -07:00
merge-base.c
merge-file.c
merge-index.c use sha1_to_hex_r() instead of strcpy 2015-10-05 11:08:05 -07:00
merge-ours.c
merge-recursive.c convert trivial sprintf / strcpy calls to xsnprintf 2015-09-25 10:18:18 -07:00
merge-tree.c
merge.c use sha1_to_hex_r() instead of strcpy 2015-10-05 11:08:05 -07:00
mktag.c
mktree.c
mv.c
name-rev.c replace trivial malloc + sprintf / strcpy calls with xstrfmt 2015-09-25 10:18:18 -07:00
notes.c Merge branch 'jk/notes-merge-config' 2015-08-31 15:39:05 -07:00
pack-objects.c Merge branch 'ah/pack-objects-usage-strings' 2015-09-01 16:31:12 -07:00
pack-redundant.c
pack-refs.c
patch-id.c
prune-packed.c
prune.c
pull.c pull: don't mark values for option "rebase" for translation 2015-09-11 09:50:00 -07:00
push.c push: add a config option push.gpgSign for default signed pushes 2015-08-19 12:58:58 -07:00
read-tree.c convert trivial sprintf / strcpy calls to xsnprintf 2015-09-25 10:18:18 -07:00
receive-pack.c receive-pack: simplify keep_arg computation 2015-10-05 11:08:05 -07:00
reflog.c Merge branch 'ah/reflog-typofix-in-error' 2015-09-01 16:31:18 -07:00
remote-ext.c remote-ext: simplify git pkt-line generation 2015-09-25 10:18:18 -07:00
remote-fd.c
remote.c
repack.c
replace.c
rerere.c rerere: release lockfile in non-writing functions 2015-09-01 15:52:54 -07:00
reset.c
rev-list.c use sha1_to_hex_r() instead of strcpy 2015-10-05 11:08:05 -07:00
rev-parse.c
revert.c
rm.c
send-pack.c push: add a config option push.gpgSign for default signed pushes 2015-08-19 12:58:58 -07:00
shortlog.c
show-branch.c show-branch: avoid segfault with --reflog of unborn branch 2015-09-25 10:18:18 -07:00
show-ref.c show-ref: place angle brackets around variables in usage string 2015-08-31 09:33:53 -07:00
stripspace.c
symbolic-ref.c
tag.c tag, update-ref: improve description of option "create-reflog" 2015-09-11 09:50:02 -07:00
unpack-file.c convert trivial sprintf / strcpy calls to xsnprintf 2015-09-25 10:18:18 -07:00
unpack-objects.c
update-index.c
update-ref.c tag, update-ref: improve description of option "create-reflog" 2015-09-11 09:50:02 -07:00
update-server-info.c
upload-archive.c upload-archive: convert sprintf to strbuf 2015-09-25 10:18:18 -07:00
var.c
verify-commit.c
verify-pack.c
verify-tag.c
worktree.c Merge branch 'jc/am-state-fix' 2015-08-31 15:39:03 -07:00
write-tree.c