mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-01-20 14:09:19 +00:00
(svn r2897) Check the return values of [cm]alloc and the length of an array, plus some smaller changes
This commit is contained in:
parent
175b2cd12a
commit
abb034c2cd
58
sound.c
58
sound.c
@ -27,13 +27,21 @@ static FileEntry* _files;
|
||||
|
||||
static void OpenBankFile(const char *filename)
|
||||
{
|
||||
uint count, i;
|
||||
uint32 size, tag;
|
||||
FileEntry* fe;
|
||||
uint count;
|
||||
uint i;
|
||||
|
||||
FioOpenFile(SOUND_SLOT, filename);
|
||||
_file_count = count = FioReadDword() >> 3;
|
||||
fe = _files = calloc(sizeof(FileEntry), count);
|
||||
count = FioReadDword() / 8;
|
||||
fe = calloc(sizeof(*fe), count);
|
||||
|
||||
if (fe == NULL) {
|
||||
_file_count = 0;
|
||||
_files = NULL;
|
||||
}
|
||||
|
||||
_file_count = count;
|
||||
_files = fe;
|
||||
|
||||
FioSeekTo(0, SEEK_SET);
|
||||
|
||||
@ -54,8 +62,8 @@ static void OpenBankFile(const char *filename)
|
||||
|
||||
// Read riff tags
|
||||
for (;;) {
|
||||
tag = FioReadDword();
|
||||
size = FioReadDword();
|
||||
uint32 tag = FioReadDword();
|
||||
uint32 size = FioReadDword();
|
||||
|
||||
if (tag == ' tmf') {
|
||||
FioReadWord(); // wFormatTag
|
||||
@ -91,14 +99,18 @@ static void OpenBankFile(const char *filename)
|
||||
|
||||
static bool SetBankSource(MixerChannel *mc, uint bank)
|
||||
{
|
||||
FileEntry *fe = &_files[bank];
|
||||
FileEntry* fe;
|
||||
int8* mem;
|
||||
uint i;
|
||||
|
||||
if (fe->file_size == 0)
|
||||
return false;
|
||||
if (bank >= _file_count) return false;
|
||||
fe = &_files[bank];
|
||||
|
||||
if (fe->file_size == 0) return false;
|
||||
|
||||
mem = malloc(fe->file_size);
|
||||
if (mem == NULL) return false;
|
||||
|
||||
mem = malloc(fe->file_size); /* XXX unchecked malloc */
|
||||
FioSeekToFile(fe->file_offset);
|
||||
FioReadBlock(mem, fe->file_size);
|
||||
|
||||
@ -121,16 +133,15 @@ bool SoundInitialize(const char *filename)
|
||||
// Low level sound player
|
||||
static void StartSound(uint sound, uint panning, uint volume)
|
||||
{
|
||||
if (volume != 0) {
|
||||
MixerChannel *mc = MxAllocateChannel(_mixer);
|
||||
if (mc == NULL)
|
||||
return;
|
||||
if (SetBankSource(mc, sound)) {
|
||||
MixerChannel* mc;
|
||||
|
||||
if (volume == 0) return;
|
||||
mc = MxAllocateChannel(_mixer);
|
||||
if (mc == NULL) return;
|
||||
if (!SetBankSource(mc, sound)) return;
|
||||
MxSetChannelVolume(mc, volume << 8, volume << 8);
|
||||
MxActivateChannel(mc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static const byte _vol_factor_by_zoom[] = {255, 190, 134};
|
||||
@ -163,19 +174,18 @@ static const byte _sound_idx[] = {
|
||||
|
||||
static void SndPlayScreenCoordFx(SoundFx sound, int x, int y)
|
||||
{
|
||||
Window *w;
|
||||
ViewPort *vp;
|
||||
int left;
|
||||
const Window* w;
|
||||
|
||||
if (msf.effect_vol == 0)
|
||||
return;
|
||||
if (msf.effect_vol == 0) return;
|
||||
|
||||
for (w = _windows; w != _last_window; w++) {
|
||||
if ((vp = w->viewport) != NULL &&
|
||||
const ViewPort* vp = w->viewport;
|
||||
|
||||
if (vp != NULL &&
|
||||
IS_INSIDE_1D(x, vp->virtual_left, vp->virtual_width) &&
|
||||
IS_INSIDE_1D(y, vp->virtual_top, vp->virtual_height)) {
|
||||
int left = ((x - vp->virtual_left) >> vp->zoom) + vp->left;
|
||||
|
||||
left = ((x - vp->virtual_left) >> vp->zoom) + vp->left;
|
||||
StartSound(
|
||||
_sound_idx[sound],
|
||||
clamp(left / 71, 0, 8),
|
||||
|
Loading…
Reference in New Issue
Block a user