SoundFile.cpp: do a NULL check before deferencing.
CID 296.
This commit is contained in:
@@ -310,7 +310,7 @@ status_t
|
|||||||
BSoundFile::_ref_to_file(const entry_ref *ref)
|
BSoundFile::_ref_to_file(const entry_ref *ref)
|
||||||
{
|
{
|
||||||
status_t status;
|
status_t status;
|
||||||
BFile * file = new BFile(ref,B_READ_ONLY);
|
BFile * file = new BFile(ref, B_READ_ONLY);
|
||||||
status = file->InitCheck();
|
status = file->InitCheck();
|
||||||
if (status != B_OK) {
|
if (status != B_OK) {
|
||||||
fSoundFile = file;
|
fSoundFile = file;
|
||||||
@@ -326,9 +326,9 @@ BSoundFile::_ref_to_file(const entry_ref *ref)
|
|||||||
media_file_format mfi;
|
media_file_format mfi;
|
||||||
media->GetFileFormatInfo(&mfi);
|
media->GetFileFormatInfo(&mfi);
|
||||||
switch (mfi.family) {
|
switch (mfi.family) {
|
||||||
case B_AIFF_FORMAT_FAMILY: fFileFormat = B_AIFF_FILE; break;
|
case B_AIFF_FORMAT_FAMILY: fFileFormat = B_AIFF_FILE; break;
|
||||||
case B_WAV_FORMAT_FAMILY: fFileFormat = B_WAVE_FILE; break;
|
case B_WAV_FORMAT_FAMILY: fFileFormat = B_WAVE_FILE; break;
|
||||||
default: fFileFormat = B_UNKNOWN_FILE; break;
|
default: fFileFormat = B_UNKNOWN_FILE; break;
|
||||||
}
|
}
|
||||||
int trackNum = 0;
|
int trackNum = 0;
|
||||||
BMediaTrack * track = 0;
|
BMediaTrack * track = 0;
|
||||||
@@ -353,29 +353,33 @@ BSoundFile::_ref_to_file(const entry_ref *ref)
|
|||||||
delete file;
|
delete file;
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
media_raw_audio_format * raw = 0;
|
media_raw_audio_format * raw = 0;
|
||||||
if (mf.type == B_MEDIA_ENCODED_AUDIO) {
|
if (mf.type == B_MEDIA_ENCODED_AUDIO) {
|
||||||
raw = &mf.u.encoded_audio.output;
|
raw = &mf.u.encoded_audio.output;
|
||||||
}
|
}
|
||||||
if (mf.type == B_MEDIA_RAW_AUDIO) {
|
if (mf.type == B_MEDIA_RAW_AUDIO) {
|
||||||
raw = &mf.u.raw_audio;
|
raw = &mf.u.raw_audio;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (raw == NULL)
|
||||||
|
return B_ERROR;
|
||||||
|
|
||||||
fSamplingRate = (int)raw->frame_rate;
|
fSamplingRate = (int)raw->frame_rate;
|
||||||
fChannelCount = raw->channel_count;
|
fChannelCount = raw->channel_count;
|
||||||
fSampleSize = raw->format & 0xf;
|
fSampleSize = raw->format & 0xf;
|
||||||
fByteOrder = raw->byte_order;
|
fByteOrder = raw->byte_order;
|
||||||
switch (raw->format) {
|
switch (raw->format) {
|
||||||
case media_raw_audio_format::B_AUDIO_FLOAT:
|
case media_raw_audio_format::B_AUDIO_FLOAT:
|
||||||
fSampleFormat = B_FLOAT_SAMPLES;
|
fSampleFormat = B_FLOAT_SAMPLES;
|
||||||
break;
|
break;
|
||||||
case media_raw_audio_format::B_AUDIO_INT:
|
case media_raw_audio_format::B_AUDIO_INT:
|
||||||
case media_raw_audio_format::B_AUDIO_SHORT:
|
case media_raw_audio_format::B_AUDIO_SHORT:
|
||||||
case media_raw_audio_format::B_AUDIO_UCHAR:
|
case media_raw_audio_format::B_AUDIO_UCHAR:
|
||||||
case media_raw_audio_format::B_AUDIO_CHAR:
|
case media_raw_audio_format::B_AUDIO_CHAR:
|
||||||
fSampleFormat = B_LINEAR_SAMPLES;
|
fSampleFormat = B_LINEAR_SAMPLES;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fSampleFormat = B_UNDEFINED_SAMPLES;
|
fSampleFormat = B_UNDEFINED_SAMPLES;
|
||||||
}
|
}
|
||||||
fByteOffset = 0;
|
fByteOffset = 0;
|
||||||
fFrameCount = track->CountFrames();
|
fFrameCount = track->CountFrames();
|
||||||
|
|||||||
Reference in New Issue
Block a user