[Vorbis-dev] [Patch] Const correct tags functions
Erik de Castro Lopo
mle+la at mega-nerd.com
Fri Aug 10 02:05:39 PDT 2007
Hi all,
I tend to compile my code with all GCC warnings turned on. However,
when I do this :
vorbis_comment_add_tag(&vdata->vc,"ENCODER","libsndfile");
I get the following warning messages:
warning: passing argument 2 of 'vorbis_comment_add_tag' discards
qualifiers from pointer target type
warning: passing argument 3 of 'vorbis_comment_add_tag' discards
qualifiers from pointer target type
The problem is that string literals like "ENCODER" are be const
char * which vorbis_comment_add_tag is prototyped as having char *
pointers, even though the strings pointed to are not modified.
The following patch (against SVN head) makes the libvorbis const
correct.
Cheers,
Erik
---------------8<---------------8<---------------8<---------------
--- include/vorbis/codec.h (revision 13502)
+++ include/vorbis/codec.h (working copy)
@@ -166,11 +166,11 @@
extern void vorbis_info_clear(vorbis_info *vi);
extern int vorbis_info_blocksize(vorbis_info *vi,int zo);
extern void vorbis_comment_init(vorbis_comment *vc);
-extern void vorbis_comment_add(vorbis_comment *vc, char *comment);
+extern void vorbis_comment_add(vorbis_comment *vc, const char *comment);
extern void vorbis_comment_add_tag(vorbis_comment *vc,
- char *tag, char *contents);
-extern char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count);
-extern int vorbis_comment_query_count(vorbis_comment *vc, char *tag);
+ const char *tag, const char *contents);
+extern char *vorbis_comment_query(vorbis_comment *vc, const char *tag, int count);
+extern int vorbis_comment_query_count(vorbis_comment *vc, const char *tag);
extern void vorbis_comment_clear(vorbis_comment *vc);
extern int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb);
--- lib/info.c (revision 13502)
+++ lib/info.c (working copy)
@@ -59,7 +59,7 @@
memset(vc,0,sizeof(*vc));
}
-void vorbis_comment_add(vorbis_comment *vc,char *comment){
+void vorbis_comment_add(vorbis_comment *vc,const char *comment){
vc->user_comments=_ogg_realloc(vc->user_comments,
(vc->comments+2)*sizeof(*vc->user_comments));
vc->comment_lengths=_ogg_realloc(vc->comment_lengths,
@@ -71,7 +71,7 @@
vc->user_comments[vc->comments]=NULL;
}
-void vorbis_comment_add_tag(vorbis_comment *vc, char *tag, char *contents){
+void vorbis_comment_add_tag(vorbis_comment *vc, const char *tag, const char *contents){
char *comment=alloca(strlen(tag)+strlen(contents)+2); /* +2 for = and \0 */
strcpy(comment, tag);
strcat(comment, "=");
@@ -91,7 +91,7 @@
return 0;
}
-char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count){
+char *vorbis_comment_query(vorbis_comment *vc, const char *tag, int count){
long i;
int found = 0;
int taglen = strlen(tag)+1; /* +1 for the = we append */
@@ -112,7 +112,7 @@
return NULL; /* didn't find anything */
}
-int vorbis_comment_query_count(vorbis_comment *vc, char *tag){
+int vorbis_comment_query_count(vorbis_comment *vc, const char *tag){
int i,count=0;
int taglen = strlen(tag)+1; /* +1 for the = we append */
char *fulltag = alloca(taglen+1);
---------------8<---------------8<---------------8<---------------
--
-----------------------------------------------------------------
Erik de Castro Lopo
-----------------------------------------------------------------
Journalist: Microsoft CEO Steve Ballmer has finally said Linux
is the No. 1 threat to Windows. What's your response to that?
Linus : "Tag, you're it." I don't care. They've had a lot of
enemies in their time. Let them fight one enemy that
doesn't care for a change.
More information about the Vorbis-dev
mailing list