{"thread":{"id":"29002","subject":"[PATCH] builtin-branch: Fix crash on invalid use of --force","startedAt":"2011-11-23T06:31:55Z","lastAt":"2011-11-23T21:30:11Z","messageCount":2,"participants":["vfr@lyx.org","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"179859","messageId":"1322029915-18486-1-git-send-email-vfr@lyx.org","threadId":"29002","inReplyTo":null,"subject":"[PATCH] builtin-branch: Fix crash on invalid use of --force","fromName":"","fromEmail":"vfr@lyx.org","sentAt":"2011-11-23T06:31:55Z","receivedAt":"2011-11-23T06:31:55Z","isPatch":true,"sender":{"key":"vfr@lyx.org","avatar":"https://avatars.githubusercontent.com/u/687868?v=4"},"body":"From: Vincent van Ravesteijn <vfr@lyx.org>\n\nThe option --force should not put us in 'create branch' mode. The\nfact that this option is only valid in 'create branch' mode is\nalready caught by the the next 'if' in which we assure that we\nare in the correct mode.\n\nWithout this patch, we end up calling create_branch without any\narguments. This means that argv[0] makes not much sense and\nthat we will finally crash because the branch name is a NULL\npointer. Hence the added safety check that we should not try\nto create a branch without a name.\n\nSigned-off-by: Vincent van Ravesteijn <vfr@lyx.org>\n---\n builtin/branch.c |    4 ++--\n 1 files changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/branch.c b/builtin/branch.c\nindex 51ca6a0..55cad76 100644\n--- a/builtin/branch.c\n+++ b/builtin/branch.c\n@@ -705,7 +705,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)\n \targc = parse_options(argc, argv, prefix, options, builtin_branch_usage,\n \t\t\t     0);\n \n-\tif (!delete && !rename && !force_create && argc == 0)\n+\tif (!delete && !rename && argc == 0)\n \t\tlist = 1;\n \n \tif (!!delete + !!rename + !!force_create + !!list > 1)\n@@ -726,7 +726,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)\n \t\t\trename_branch(argv[0], argv[1], rename > 1);\n \t\telse\n \t\t\tusage_with_options(builtin_branch_usage, options);\n-\t} else if (argc <= 2) {\n+\t} else if (argc > 0 && argc <= 2) {\n \t\tif (kinds != REF_LOCAL_BRANCH)\n \t\t\tdie(_(\"-a and -r options to 'git branch' do not make sense with a branch name\"));\n \t\tcreate_branch(head, argv[0], (argc == 2) ? argv[1] : head,\n-- \n1.7.8-rc3\n"},{"id":"179913","messageId":"7vsjlea5ng.fsf@alter.siamese.dyndns.org","threadId":"29002","inReplyTo":"1322029915-18486-1-git-send-email-vfr@lyx.org","subject":"Re: [PATCH] builtin-branch: Fix crash on invalid use of --force","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2011-11-23T21:30:11Z","receivedAt":"2011-11-23T21:30:11Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Makes sense and is a nice fix for a regression on 'master'. Thanks.\n"}]}