From: vfr@lyx.org
To: git@vger.kernel.org
Cc: gitster@pobox.com, Vincent van Ravesteijn <vfr@lyx.org>
Subject: [PATCH] builtin-branch: Fix crash on invalid use of --force
Date: Wed, 23 Nov 2011 07:31:55 +0100 [thread overview]
Message-ID: <1322029915-18486-1-git-send-email-vfr@lyx.org> (raw)
From: Vincent van Ravesteijn <vfr@lyx.org>
The option --force should not put us in 'create branch' mode. The
fact that this option is only valid in 'create branch' mode is
already caught by the the next 'if' in which we assure that we
are in the correct mode.
Without this patch, we end up calling create_branch without any
arguments. This means that argv[0] makes not much sense and
that we will finally crash because the branch name is a NULL
pointer. Hence the added safety check that we should not try
to create a branch without a name.
Signed-off-by: Vincent van Ravesteijn <vfr@lyx.org>
---
builtin/branch.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/builtin/branch.c b/builtin/branch.c
index 51ca6a0..55cad76 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -705,7 +705,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
argc = parse_options(argc, argv, prefix, options, builtin_branch_usage,
0);
- if (!delete && !rename && !force_create && argc == 0)
+ if (!delete && !rename && argc == 0)
list = 1;
if (!!delete + !!rename + !!force_create + !!list > 1)
@@ -726,7 +726,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
rename_branch(argv[0], argv[1], rename > 1);
else
usage_with_options(builtin_branch_usage, options);
- } else if (argc <= 2) {
+ } else if (argc > 0 && argc <= 2) {
if (kinds != REF_LOCAL_BRANCH)
die(_("-a and -r options to 'git branch' do not make sense with a branch name"));
create_branch(head, argv[0], (argc == 2) ? argv[1] : head,
--
1.7.8-rc3
next reply other threads:[~2011-11-23 6:33 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-23 6:31 vfr [this message]
2011-11-23 21:30 ` [PATCH] builtin-branch: Fix crash on invalid use of --force Junio C Hamano
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=1322029915-18486-1-git-send-email-vfr@lyx.org \
--to=vfr@lyx.org \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/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).