* [PATCH]: tree-walk.h: Warning fix
@ 2007-06-20 2:11 Luiz Fernando N. Capitulino
2007-06-23 6:19 ` Junio C Hamano
0 siblings, 1 reply; 3+ messages in thread
From: Luiz Fernando N. Capitulino @ 2007-06-20 2:11 UTC (permalink / raw)
To: gitster; +Cc: git
Code that is using libgit.a, and hence including GIT's headers, may
get this warning:
"""
../tree-walk.h: In function 'tree_entry_len':
../tree-walk.h:25: warning: cast discards qualifiers from pointer target type
../tree-walk.h:25: warning: cast discards qualifiers from pointer target type
"""
This happens because the cast used in tree_entry_len() is discarding
the const qualifier (thanks to Shawn Pearce by noticing this).
Signed-off-by: Luiz Fernando N. Capitulino <lcapitulino@gmail.com>
diff --git a/tree-walk.h b/tree-walk.h
index ee747ab..625198f 100644
--- a/tree-walk.h
+++ b/tree-walk.h
@@ -22,7 +22,7 @@ static inline const unsigned char *tree_entry_extract(struct tree_desc *desc, co
static inline int tree_entry_len(const char *name, const unsigned char *sha1)
{
- return (char *)sha1 - (char *)name - 1;
+ return (const char *)sha1 - (const char *)name - 1;
}
void update_tree_entry(struct tree_desc *);
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH]: tree-walk.h: Warning fix
2007-06-20 2:11 [PATCH]: tree-walk.h: Warning fix Luiz Fernando N. Capitulino
@ 2007-06-23 6:19 ` Junio C Hamano
2007-06-24 2:10 ` Luiz Fernando N. Capitulino
0 siblings, 1 reply; 3+ messages in thread
From: Junio C Hamano @ 2007-06-23 6:19 UTC (permalink / raw)
To: Luiz Fernando N. Capitulino; +Cc: git
"Luiz Fernando N. Capitulino" <lcapitulino@mandriva.com.br>
writes:
> diff --git a/tree-walk.h b/tree-walk.h
> index ee747ab..625198f 100644
> --- a/tree-walk.h
> +++ b/tree-walk.h
> @@ -22,7 +22,7 @@ static inline const unsigned char *tree_entry_extract(struct tree_desc *desc, co
>
> static inline int tree_entry_len(const char *name, const unsigned char *sha1)
> {
> - return (char *)sha1 - (char *)name - 1;
> + return (const char *)sha1 - (const char *)name - 1;
> }
>
> void update_tree_entry(struct tree_desc *);
Grumble. Incoming "name" is already (const char*), isn't it?
I'd cast only the sha1 side and apply.
However, I think -Wcast-qual is a pretty useless option.
The nastiest one, if you care, is exec_cmd.c::execv_git_cmd()
where we never muck with "const char **argv" ourselves, but we
have to call execve(), which takes (char**) as its second
parameter. We cast away constness for that call; otherwise you
would then get prototype mismatch.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH]: tree-walk.h: Warning fix
2007-06-23 6:19 ` Junio C Hamano
@ 2007-06-24 2:10 ` Luiz Fernando N. Capitulino
0 siblings, 0 replies; 3+ messages in thread
From: Luiz Fernando N. Capitulino @ 2007-06-24 2:10 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
Em Fri, 22 Jun 2007 23:19:55 -0700
Junio C Hamano <gitster@pobox.com> escreveu:
| "Luiz Fernando N. Capitulino" <lcapitulino@mandriva.com.br>
| writes:
|
| > diff --git a/tree-walk.h b/tree-walk.h
| > index ee747ab..625198f 100644
| > --- a/tree-walk.h
| > +++ b/tree-walk.h
| > @@ -22,7 +22,7 @@ static inline const unsigned char *tree_entry_extract(struct tree_desc *desc, co
| >
| > static inline int tree_entry_len(const char *name, const unsigned char *sha1)
| > {
| > - return (char *)sha1 - (char *)name - 1;
| > + return (const char *)sha1 - (const char *)name - 1;
| > }
| >
| > void update_tree_entry(struct tree_desc *);
|
| Grumble. Incoming "name" is already (const char*), isn't it?
| I'd cast only the sha1 side and apply.
Yes, you're right. I'll fix it and apply again.
Thanks a lot for the feedback.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2007-06-24 2:10 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-06-20 2:11 [PATCH]: tree-walk.h: Warning fix Luiz Fernando N. Capitulino
2007-06-23 6:19 ` Junio C Hamano
2007-06-24 2:10 ` Luiz Fernando N. Capitulino
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).