I've run into strange problems making a Libsndfile-based audio app on OSX. The data in read and written buffers got corrupted in strange and unpredictable ways.
Here is a short program that reproduces the problem for me:
#include <iostream>
#include "sndfile.h"
int main(int argc, const char * argv[])
{
float* buffer = (float*)malloc(4096*sizeof(float));
SNDFILE* file;
SF_INFO infos;
infos.format = 0;
file = sf_open("ABCD.WAV",SFM_READ,&infos);
if (file==NULL)
{
std::cout << "LIBSNDFILE ERROR: " << sf_strerror(file) << "\n";
}
int samplesread=1;
while (samplesread!=0)
{
samplesread = sf_readf_float(file,buffer,4096);
std::cout << " " << samplesread;
}
std::cout << "";
sf_close(file);
free(buffer);
return 0;
}
The program compiles and runs fine but running it with Valgrind reveals this kind of errors:
==933== Invalid write of size 8
==933== at 0x56EF4B: _platform_bzero$VARIANT$Merom (in /usr/lib/system/libsystem_platform.dylib)
==933== by 0x2FDBB: psf_memset (in /opt/local/lib/libsndfile.1.dylib)
==933== by 0x11E0B: sf_readf_float (in /opt/local/lib/libsndfile.1.dylib)
==933== by 0x100001323: main (in ./sndfiletest)
==933== Address 0x873270 is 0 bytes after a block of size 16,384 alloc'd
==933== at 0x4711: malloc (vg_replace_malloc.c:296)
==933== by 0x100001287: main (in ./sndfiletest
Thanks for any help in advance -T