git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] cat-file: Move assignment to the buffer declaration
@ 2015-01-08 18:20 Alexander Kuleshov
  2015-01-08 19:31 ` Junio C Hamano
  0 siblings, 1 reply; 2+ messages in thread
From: Alexander Kuleshov @ 2015-01-08 18:20 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, Alexander Kuleshov

Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>
---
 builtin/cat-file.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index f8d8129..840ace2 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -17,14 +17,13 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
 {
 	unsigned char sha1[20];
 	enum object_type type;
-	char *buf;
+	char *buf = NULL;
 	unsigned long size;
 	struct object_context obj_context;
 
 	if (get_sha1_with_context(obj_name, 0, sha1, &obj_context))
 		die("Not a valid object name %s", obj_name);
 
-	buf = NULL;
 	switch (opt) {
 	case 't':
 		type = sha1_object_info(sha1, NULL);
-- 
2.2.1.268.g1e6f5b2.dirty

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] cat-file: Move assignment to the buffer declaration
  2015-01-08 18:20 [PATCH] cat-file: Move assignment to the buffer declaration Alexander Kuleshov
@ 2015-01-08 19:31 ` Junio C Hamano
  0 siblings, 0 replies; 2+ messages in thread
From: Junio C Hamano @ 2015-01-08 19:31 UTC (permalink / raw)
  To: Alexander Kuleshov; +Cc: git

Alexander Kuleshov <kuleshovmail@gmail.com> writes:

> Subject: Re: [PATCH] cat-file: Move assignment to the buffer declaration

"git shortlog" on recent history shows that it is conventional not
to upcase the sentence after the "<area>:" on titles.

This line not just "declares" but "defines" buf, so I'd phrase it
more like:

	cat-file: initialize buf to NULL at its definition

	This way is shorter than with a separate assignment.

or somesuch.

If two people posted two patches to add a new cat-file.c file and
one patch did it the way the current code does while the other patch
did it the way the code with this patch does, I would likely to pick
the latter, because it is more concise and it is more clear that
there is less chance that buf could be used uninitialized.

To be bluntly honest, however, it's such a minor thing that once it
_is_ in the tree, it's not really worth the patch noise to go and
fix it up.

> Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com>
> ---
>  builtin/cat-file.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/builtin/cat-file.c b/builtin/cat-file.c
> index f8d8129..840ace2 100644
> --- a/builtin/cat-file.c
> +++ b/builtin/cat-file.c
> @@ -17,14 +17,13 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name)
>  {
>  	unsigned char sha1[20];
>  	enum object_type type;
> -	char *buf;
> +	char *buf = NULL;
>  	unsigned long size;
>  	struct object_context obj_context;
>  
>  	if (get_sha1_with_context(obj_name, 0, sha1, &obj_context))
>  		die("Not a valid object name %s", obj_name);
>  
> -	buf = NULL;



>  	switch (opt) {
>  	case 't':
>  		type = sha1_object_info(sha1, NULL);

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-01-08 19:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-08 18:20 [PATCH] cat-file: Move assignment to the buffer declaration Alexander Kuleshov
2015-01-08 19:31 ` Junio C Hamano

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).