{"thread":{"id":"8657","subject":"[PATCH]: tree-walk.h: Warning fix","startedAt":"2007-06-20T02:11:27Z","lastAt":"2007-06-24T02:10:21Z","messageCount":3,"participants":["Luiz Fernando N. Capitulino","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"45392","messageId":"20070619231127.7ffe273b@gnut","threadId":"8657","inReplyTo":null,"subject":"[PATCH]: tree-walk.h: Warning fix","fromName":"Luiz Fernando N. Capitulino","fromEmail":"lcapitulino@mandriva.com.br","sentAt":"2007-06-20T02:11:27Z","receivedAt":"2007-06-20T02:11:27Z","isPatch":true,"sender":{"key":"lcapitulino@mandriva.com.br","avatar":null},"body":"\nCode that is using libgit.a, and hence including GIT's headers, may\nget this warning:\n\n\"\"\"\n../tree-walk.h: In function 'tree_entry_len':\n../tree-walk.h:25: warning: cast discards qualifiers from pointer target type\n../tree-walk.h:25: warning: cast discards qualifiers from pointer target type\n\"\"\"\n\nThis happens because the cast used in tree_entry_len() is discarding\nthe const qualifier (thanks to Shawn Pearce by noticing this).\n\nSigned-off-by: Luiz Fernando N. Capitulino <lcapitulino@gmail.com>\n\ndiff --git a/tree-walk.h b/tree-walk.h\nindex ee747ab..625198f 100644\n--- a/tree-walk.h\n+++ b/tree-walk.h\n@@ -22,7 +22,7 @@ static inline const unsigned char *tree_entry_extract(struct tree_desc *desc, co\n \n static inline int tree_entry_len(const char *name, const unsigned char *sha1)\n {\n-\treturn (char *)sha1 - (char *)name - 1;\n+\treturn (const char *)sha1 - (const char *)name - 1;\n }\n \n void update_tree_entry(struct tree_desc *);\n"},{"id":"45592","messageId":"7v1wg39oqc.fsf@assigned-by-dhcp.pobox.com","threadId":"8657","inReplyTo":"20070619231127.7ffe273b@gnut","subject":"Re: [PATCH]: tree-walk.h: Warning fix","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-06-23T06:19:55Z","receivedAt":"2007-06-23T06:19:55Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Luiz Fernando N. Capitulino\" <lcapitulino@mandriva.com.br>\nwrites:\n\n> diff --git a/tree-walk.h b/tree-walk.h\n> index ee747ab..625198f 100644\n> --- a/tree-walk.h\n> +++ b/tree-walk.h\n> @@ -22,7 +22,7 @@ static inline const unsigned char *tree_entry_extract(struct tree_desc *desc, co\n>  \n>  static inline int tree_entry_len(const char *name, const unsigned char *sha1)\n>  {\n> -\treturn (char *)sha1 - (char *)name - 1;\n> +\treturn (const char *)sha1 - (const char *)name - 1;\n>  }\n>  \n>  void update_tree_entry(struct tree_desc *);\n\nGrumble.  Incoming \"name\" is already (const char*), isn't it?\nI'd cast only the sha1 side and apply.\n\nHowever, I think -Wcast-qual is a pretty useless option.  \n\nThe nastiest one, if you care, is exec_cmd.c::execv_git_cmd()\nwhere we never muck with \"const char **argv\" ourselves, but we\nhave to call execve(), which takes (char**) as its second\nparameter.  We cast away constness for that call; otherwise you\nwould then get prototype mismatch.\n"},{"id":"45638","messageId":"20070623231021.40a6f3be@gnut","threadId":"8657","inReplyTo":"7v1wg39oqc.fsf@assigned-by-dhcp.pobox.com","subject":"Re: [PATCH]: tree-walk.h: Warning fix","fromName":"Luiz Fernando N. Capitulino","fromEmail":"lcapitulino@mandriva.com.br","sentAt":"2007-06-24T02:10:21Z","receivedAt":"2007-06-24T02:10:21Z","isPatch":true,"sender":{"key":"lcapitulino@mandriva.com.br","avatar":null},"body":"Em Fri, 22 Jun 2007 23:19:55 -0700\nJunio C Hamano <gitster@pobox.com> escreveu:\n\n| \"Luiz Fernando N. Capitulino\" <lcapitulino@mandriva.com.br>\n| writes:\n| \n| > diff --git a/tree-walk.h b/tree-walk.h\n| > index ee747ab..625198f 100644\n| > --- a/tree-walk.h\n| > +++ b/tree-walk.h\n| > @@ -22,7 +22,7 @@ static inline const unsigned char *tree_entry_extract(struct tree_desc *desc, co\n| >  \n| >  static inline int tree_entry_len(const char *name, const unsigned char *sha1)\n| >  {\n| > -\treturn (char *)sha1 - (char *)name - 1;\n| > +\treturn (const char *)sha1 - (const char *)name - 1;\n| >  }\n| >  \n| >  void update_tree_entry(struct tree_desc *);\n| \n| Grumble.  Incoming \"name\" is already (const char*), isn't it?\n| I'd cast only the sha1 side and apply.\n\n Yes, you're right. I'll fix it and apply again.\n\n Thanks a lot for the feedback.\n"}]}