{"thread":{"id":"38315","subject":"[PATCH] cat-file: Move assignment to the buffer declaration","startedAt":"2015-01-08T18:20:03Z","lastAt":"2015-01-08T19:31:46Z","messageCount":2,"participants":["Alexander Kuleshov","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"254473","messageId":"1420741203-21107-1-git-send-email-kuleshovmail@gmail.com","threadId":"38315","inReplyTo":null,"subject":"[PATCH] cat-file: Move assignment to the buffer declaration","fromName":"Alexander Kuleshov","fromEmail":"kuleshovmail@gmail.com","sentAt":"2015-01-08T18:20:03Z","receivedAt":"2015-01-08T18:20:03Z","isPatch":true,"sender":{"key":"kuleshovmail@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2699235?v=4"},"body":"Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>\n---\n builtin/cat-file.c | 3 +--\n 1 file changed, 1 insertion(+), 2 deletions(-)\n\ndiff --git a/builtin/cat-file.c b/builtin/cat-file.c\nindex f8d8129..840ace2 100644\n--- a/builtin/cat-file.c\n+++ b/builtin/cat-file.c\n@@ -17,14 +17,13 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)\n {\n \tunsigned char sha1[20];\n \tenum object_type type;\n-\tchar *buf;\n+\tchar *buf = NULL;\n \tunsigned long size;\n \tstruct object_context obj_context;\n \n \tif (get_sha1_with_context(obj_name, 0, sha1, &obj_context))\n \t\tdie(\"Not a valid object name %s\", obj_name);\n \n-\tbuf = NULL;\n \tswitch (opt) {\n \tcase 't':\n \t\ttype = sha1_object_info(sha1, NULL);\n-- \n2.2.1.268.g1e6f5b2.dirty\n"},{"id":"254479","messageId":"xmqq61chf4rh.fsf@gitster.dls.corp.google.com","threadId":"38315","inReplyTo":"1420741203-21107-1-git-send-email-kuleshovmail@gmail.com","subject":"Re: [PATCH] cat-file: Move assignment to the buffer declaration","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-01-08T19:31:46Z","receivedAt":"2015-01-08T19:31:46Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Alexander Kuleshov <kuleshovmail@gmail.com> writes:\n\n> Subject: Re: [PATCH] cat-file: Move assignment to the buffer declaration\n\n\"git shortlog\" on recent history shows that it is conventional not\nto upcase the sentence after the \"<area>:\" on titles.\n\nThis line not just \"declares\" but \"defines\" buf, so I'd phrase it\nmore like:\n\n\tcat-file: initialize buf to NULL at its definition\n\n\tThis way is shorter than with a separate assignment.\n\nor somesuch.\n\nIf two people posted two patches to add a new cat-file.c file and\none patch did it the way the current code does while the other patch\ndid it the way the code with this patch does, I would likely to pick\nthe latter, because it is more concise and it is more clear that\nthere is less chance that buf could be used uninitialized.\n\nTo be bluntly honest, however, it's such a minor thing that once it\n_is_ in the tree, it's not really worth the patch noise to go and\nfix it up.\n\n> Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>\n> ---\n>  builtin/cat-file.c | 3 +--\n>  1 file changed, 1 insertion(+), 2 deletions(-)\n>\n> diff --git a/builtin/cat-file.c b/builtin/cat-file.c\n> index f8d8129..840ace2 100644\n> --- a/builtin/cat-file.c\n> +++ b/builtin/cat-file.c\n> @@ -17,14 +17,13 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)\n>  {\n>  \tunsigned char sha1[20];\n>  \tenum object_type type;\n> -\tchar *buf;\n> +\tchar *buf = NULL;\n>  \tunsigned long size;\n>  \tstruct object_context obj_context;\n>  \n>  \tif (get_sha1_with_context(obj_name, 0, sha1, &obj_context))\n>  \t\tdie(\"Not a valid object name %s\", obj_name);\n>  \n> -\tbuf = NULL;\n\n\n\n>  \tswitch (opt) {\n>  \tcase 't':\n>  \t\ttype = sha1_object_info(sha1, NULL);\n"}]}