[Scummvm-devel] Re: [Scummvm-cvs-logs] CVS: scummvm/scumm sound.cpp,1.133,1.134

Max Horn max at quendi.de
Fri Jun 13 13:41:09 CEST 2003


Am Freitag, 13.06.03 um 20:09 Uhr schrieb Torbj?rn Andersson:

> Update of /cvsroot/scummvm/scummvm/scumm
> In directory sc8-pr-cvs1:/tmp/cvs-serv10063
>
> Modified Files:
> 	sound.cpp
> Log Message:
> Cast %c error() parameters to byte before printing, like we do 
> elsewhere.
>
>
[...]
>  				default:
> -					error("Unknown sound header %c%c%c%c", tag>>24, tag>>16, tag>>8, 
> tag);
> +					error("Unknown sound header %c%c%c%c",
> +						(byte)(tag >> 24),
> +						(byte)(tag >> 16),
> +						(byte)(tag >> 8),
> +						(byte)tag);
>  				}

Note: this code (and similar code which occurs  in several other 
places) has been a thorn in my side for some time now. Because it's not 
endian safe, it'll print the tag in reverse order on BE systems. A 
solution would be to add a simple helper function, like this:

const char *tagToString(uint32 tag) {
   static char buffer[5] = "1234";
   .... // Fill buffer with tag in an endian safe way, if necessary 
using #ifdefs
}

Then we can use that in all those places, resulting in shorter and 
endian safe code... of course this function wouldn't be thread safe, 
but I hardly see that as a problem (but if desired we can also easily 
make a thread safe version by passing in a char buffer as parameters).


Max





More information about the Scummvm-devel mailing list