[flac-dev] [PATCH] Add missing functions to VorbisComment class + a few other things

Bastiaan Timmer basjetimmer at yahoo.com
Mon May 7 15:48:13 PDT 2012


> While you are at it, can you check/fix the following warning
> ?
> 
> metadata.cpp:812:98: warning: narrowing conversion of
> 'strlen(((const 
> char*)string))' from 'size_t {aka long unsigned int}' to
> 'FLAC__uint32 
> {aka unsigned int}' inside { } is ill-formed in C++11
> [-Wnarrowing]
> 
> 
> Thanks !

Yeah sure! I don't get that error because I'm on a 32 bit OS by the way. The message makes it pretty clear you are compiling on 64 bit, so the size_t returned by strlen is 64 bits, but FLAC__StreamMetadata_VorbisComment_Entry expects a FLAC__uint32 (which is obviously 32 bits), so gcc warns/errors that the size_t might not fit. I can think of two solutions:
1. Make the FLAC__StreamMetadata_VorbisComment_Entry struct's 'length' member a FLAC__uint64.
2. static_cast the return value of strlen to 32 bits...

I'd say option 2 is easiest, as I don't know what else will be affected by changing the size of FLAC__StreamMetadata_VorbisComment_Entry. The only problem with option 2 would be if the vendor string ever gets larger than ~4.3 billion characters, but I don't think vorbis comments support values that large anyway.

Anyway, here's a patch that casts to FLAC__uint32, Note I have the offending code on a very different line number (current git I think), so this patch may not apply cleanly. But it's a one-liner anyway (a one-worder actually), so you could just read it and apply it manually...

Also, I don't know if such a cast is considered an expensive operation, but in that case it might be possible to first check the size of size_t (during preprocessing) to see if it is larger than 32 bits. The cast is unnecessary if it is not.

Bas
-------------- next part --------------
A non-text attachment was scrubbed...
Name: narrowing_patch
Type: application/octet-stream
Size: 800 bytes
Desc: not available
Url : http://lists.xiph.org/pipermail/flac-dev/attachments/20120507/8342f893/attachment-0001.obj 


More information about the flac-dev mailing list