Erik de Castro Lopo
2007-Aug-10 02:06 UTC
[Vorbis-dev] [Patch] Const correct tags functions
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.
Erik de Castro Lopo
2007-Aug-14 05:55 UTC
[Vorbis-dev] [Patch] Const correct tags functions
Erik de Castro Lopo wrote:> 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.Is someone able to take a look at this patch? Erik -- ----------------------------------------------------------------- Erik de Castro Lopo ----------------------------------------------------------------- "Microsoft, and other companies with shoddy security, ....." -- Bruce Schneier, cryto-guru, to a US Senate committee.
On 14/08/07, Erik de Castro Lopo <mle+la@mega-nerd.com> wrote:> Erik de Castro Lopo wrote: > > > 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. > > Is someone able to take a look at this patch?The maintainer of libvorbis is Monty. Ping him on IRC, point to the trac bug which includes this patch, wait. cheers, kfish.
Erik de Castro Lopo
2007-Aug-14 20:12 UTC
[Vorbis-dev] [Patch] Const correct tags functions
Erik de Castro Lopo wrote:> Is someone able to take a look at this patch?If it helps, this is now in trac: https://trac.xiph.org/ticket/1228 Erik -- ----------------------------------------------------------------- Erik de Castro Lopo ----------------------------------------------------------------- Being really good at C++ is like being really good at using rocks to sharpen sticks." -- Thant Tessman
Erik de Castro Lopo
2007-Aug-19 04:09 UTC
[Vorbis-dev] [Patch] Const correct tags functions
Erik de Castro Lopo wrote:> If it helps, this is now in trac: > > https://trac.xiph.org/ticket/1228Fixed in SVN 13571.> Erik > -- > ----------------------------------------------------------------- > Erik de Castro Lopo > ----------------------------------------------------------------- > Being really good at C++ is like being really good at using rocks to > sharpen sticks." -- Thant Tessman > _______________________________________________ > Vorbis-dev mailing list > Vorbis-dev@xiph.org > http://lists.xiph.org/mailman/listinfo/vorbis-dev >-- ----------------------------------------------------------------- Erik de Castro Lopo ----------------------------------------------------------------- "The fury with which untenable beliefs are defended is inversely proportional to their defensibility." -- Richard Dawkins