Skip to content

Commit

Permalink
static code analysis fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jarikomppa committed Apr 5, 2020
1 parent 86940f9 commit d72f30d
Show file tree
Hide file tree
Showing 16 changed files with 71 additions and 123 deletions.
2 changes: 1 addition & 1 deletion demos/megademo/space.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ namespace space
"parts of the audio pipeline.";
char temp[512];
int i = 0;
while (s[i] && i < (tick - gTickofs) / 70)
while (i < (tick - gTickofs) / 70 && s[i])
{
temp[i] = s[i];
i++;
Expand Down
2 changes: 2 additions & 0 deletions include/soloud_vizsn.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ namespace SoLoud

float resonate(float i);
float antiresonate(float i);
VizsnResonator();
};

struct VizsnBank
{
VizsnResonator r[10];
float pitch;
float frica, voice, aspir, bypas, breth;
VizsnBank();
};

class VizsnInstance : public AudioSourceInstance
Expand Down
5 changes: 5 additions & 0 deletions src/audiosource/ay/soloud_ay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ namespace SoLoud
mBaseSamplerate = 44100;
mChannels = 2;
mOps = 0;
mYm = false;
mChipspeed = 1774400;
mCpuspeed = 50;
mLooppos = 0;
mLength = 0;
}

Ay::~Ay()
Expand Down
4 changes: 2 additions & 2 deletions src/audiosource/tedsid/sid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ void SIDsound::setModel(unsigned int model)
(20163.0 - 1315.0) * x + 1315.0;
}
dcWave = 0x380;
dcMixer = -0xFFF*0xFF/18 >> 7;
dcMixer = -454; // gcc and msvc agree that "-0xFFF * 0xFF / 18 >> 7" turns into -454;
dcVoice = 0x800*0xFF;
break;

Expand All @@ -111,7 +111,7 @@ void SIDsound::setModel(unsigned int model)
* (18000.0 - 4600.0) + 4600.0;
}
dcWave = 0x380;
dcMixer = -0xFFF*0xFF/18 >> 7;
dcMixer = -454; // gcc and msvc agree that "-0xFFF * 0xFF / 18 >> 7" turns into -454;
dcVoice = 0x800*0xFF;
break;
}
Expand Down
1 change: 1 addition & 0 deletions src/audiosource/tedsid/soloud_tedsid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ namespace SoLoud
mOps = 0;
mModel = 0;
mLength = 0;
mLooppos = 0;
}

TedSid::~TedSid()
Expand Down
11 changes: 7 additions & 4 deletions src/audiosource/vizsn/soloud_vizsn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ static const char keyz[] =

namespace SoLoud
{
VizsnResonator::VizsnResonator() : a(0), b(0), c(0), p1(0), p2(0) {}
VizsnBank::VizsnBank() : pitch(0), frica(0), voice(0), aspir(0), bypas(0), breth(0) {}

float VizsnResonator::resonate(float i)
{
float x = (a * i) + (b * p1) + (c * p2);
Expand Down Expand Up @@ -431,11 +434,11 @@ namespace SoLoud
/* v */
const float *v = voo[aP - 8];

aB->voice = *v++;
/*aB->voice =*/ *v++;
aB->aspir = *v++;
aB->frica = *v++;
aB->bypas = *v++;
aB->breth = *v++;
/*aB->breth =*/ *v++;

int j;
for (j = 0; j < 10; j++)
Expand Down Expand Up @@ -515,8 +518,8 @@ namespace SoLoud
for (i = 0; i < len; i++)
{
int c = mText[i + 1];
if (c == '\x84' || c == -124) c = '{'; // ä
if (c == '\x94' || c == -108) c = '|'; // ö
if (c == '\x84') c = '{'; // ä
if (c == '\x94') c = '|'; // ö
if (c >= 'a' && c <= '|')
{
mText[i + 1] = keyz[c - 'a'];
Expand Down
6 changes: 4 additions & 2 deletions src/tools/ay2zak/pt3song.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,9 @@ bool PT3Player::GetTime(unsigned& time, unsigned& loop)
pat[0].ch[0].a = pat[0].ch[1].a = pat[0].ch[2].a = 1;
if (TS != 0x20) {
fastInitPattern(pat[1], TS * 3 - 3 - chip[0].header->PositionList[i]);
pat[1].ch[0].a = pat[1].ch[0].a = pat[1].ch[0].a = 1;
// no idea what the idea here was, maybe it was upposed to be ch0,1,2?
//pat[1].ch[0].a = pat[1].ch[0].a = pat[1].ch[0].a = 1;
pat[1].ch[0].a = 1;
}

for (;;) {
Expand Down Expand Up @@ -747,7 +749,7 @@ PT3Song::PT3Song(FILE* ff) : ChipSong(ff)

PT3Song::~PT3Song()
{
free(player);
delete player;
}

ChipPlayer *PT3Song::CreatePlayer(unsigned sample_fq)
Expand Down
3 changes: 2 additions & 1 deletion src/tools/ay2zak/sndbuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ SNDBUFFER::SNDBUFFER(unsigned size) {
// size must be power of 2 for faster calc cyclic position: pos = (pos+1) & (size-1)
if (size & (size-1)) {
unsigned i = 1;
for (i = 1; i < size; i *= 2);
while (i < size) i *= 2;
size = i;
}
SNDBUFFER::size = size;
buffer = (SNDSAMPLE*)malloc(size * sizeof(SNDSAMPLE));
samples_ready = 0;
reset();
}

Expand Down
4 changes: 1 addition & 3 deletions src/tools/ay2zak/sndrender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void SNDRENDER::end_frame(unsigned endframe_sys_tick)
unsigned ready_samples = dstpos - dst_start;
if ((int)ready_samples < 0) ready_samples += bufsize;
tick -= (ready_samples << TICK_FF);
passed_snd_ticks += (ready_samples << TICK_FF);
passed_snd_ticks += ((uint64_t)ready_samples << TICK_FF);
}

void SNDRENDER::set_timings(unsigned sys_clock_rate, unsigned sample_rate)
Expand Down Expand Up @@ -88,8 +88,6 @@ void SNDRENDER::flush(unsigned endtick)
s1_l += mix_l * scale;
s1_r += mix_r * scale;

tick = endtick;

} else {
scale = filter_sum_full_u - filter_diff[(tick & (TICK_F-1)) + TICK_F];

Expand Down
2 changes: 1 addition & 1 deletion src/tools/ay2zak/z80esong.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Z80EmulatedSong : public ChipSong
public:

virtual ChipPlayer *CreatePlayer(unsigned sample_fq);
Z80EmulatedSong(FILE *file) : ChipSong(file) {}
Z80EmulatedSong(FILE *file) : ChipSong(file), frame(0), frame_start(0), done(0) {}

void reg_out(unsigned char activereg, unsigned char val);
virtual void z80_int_hook() {}
Expand Down
127 changes: 30 additions & 97 deletions src/tools/codegen/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -737,46 +737,22 @@ void emit_cppend(FILE * f)
void emit_func(FILE * f, int aClass, int aMethod)
{
int i;
int initfunc = 0;
Class *c = gClass[aClass];
Method *m = c->mMethod[aMethod];

if (c->mName == "Soloud" && m->mFuncName.find("_init") != string::npos)
{
// Init function, needs "a bit" of special handling.
initfunc = 1;
string fn = OUTDIR "soloud_c_" + m->mFuncName.substr(0, m->mFuncName.find_first_of('_')) + ".cpp";
f = fopen(fn.c_str(), "w");
fileheader(f);
emit_cppstart(f);
}

if (initfunc)
{
fprintf(f,
"%s %s_%s(",
m->mRetType.c_str(),
c->mName.c_str(),
m->mFuncName.c_str());
}
else
{
fprintf(f,
"%s %s_%s(void * aClassPtr",
m->mRetType.c_str(),
c->mName.c_str(),
m->mFuncName.c_str());
}
fprintf(f,
"%s %s_%s(void * aClassPtr",
m->mRetType.c_str(),
c->mName.c_str(),
m->mFuncName.c_str());

int had_defaults = 0;
for (i = 0; i < (signed)m->mParmName.size(); i++)
{
if (m->mParmValue[i] == "")
{
if (!(i == 0 && initfunc))
fprintf(f, ", ");
fprintf(f,
"%s %s",
", %s %s",
m->mParmType[i].c_str(),
m->mParmName[i].c_str());
}
Expand All @@ -786,27 +762,15 @@ void emit_func(FILE * f, int aClass, int aMethod)
}
}

if (initfunc)
{
fprintf(f,
")\n"
"{\n"
"\t%s%s(",
(m->mRetType == "void")?"":"return ",
m->mFuncName.c_str());
}
else
{
fprintf(f,
")\n"
"{\n"
"\t%s * cl = (%s *)aClassPtr;\n"
"\t%scl->%s(",
c->mName.c_str(),
c->mName.c_str(),
(m->mRetType == "void")?"":"return ",
m->mFuncName.c_str());
}
fprintf(f,
")\n"
"{\n"
"\t%s * cl = (%s *)aClassPtr;\n"
"\t%scl->%s(",
c->mName.c_str(),
c->mName.c_str(),
(m->mRetType == "void")?"":"return ",
m->mFuncName.c_str());

for (i = 0; i < (signed)m->mParmName.size(); i++)
{
Expand All @@ -829,53 +793,28 @@ void emit_func(FILE * f, int aClass, int aMethod)

if (had_defaults)
{
if (initfunc)
{
fprintf(f,
"%s %s_%sEx(",
m->mRetType.c_str(),
c->mName.c_str(),
m->mFuncName.c_str());
}
else
{
fprintf(f,
"%s %s_%sEx(void * aClassPtr",
m->mRetType.c_str(),
c->mName.c_str(),
m->mFuncName.c_str());
}
fprintf(f,
"%s %s_%sEx(void * aClassPtr",
m->mRetType.c_str(),
c->mName.c_str(),
m->mFuncName.c_str());
for (i =0; i < (signed)m->mParmName.size(); i++)
{
if (!(i == 0 && initfunc))
fprintf(f, ", ");
fprintf(f,
"%s %s",
", %s %s",
m->mParmType[i].c_str(),
m->mParmName[i].c_str());
}

if (initfunc)
{
fprintf(f,
")\n"
"{\n"
"\t%s%s(",
(m->mRetType == "void")?"":"return ",
m->mFuncName.c_str());
}
else
{
fprintf(f,
")\n"
"{\n"
"\t%s * cl = (%s *)aClassPtr;\n"
"\t%scl->%s(",
c->mName.c_str(),
c->mName.c_str(),
(m->mRetType == "void")?"":"return ",
m->mFuncName.c_str());
}
fprintf(f,
")\n"
"{\n"
"\t%s * cl = (%s *)aClassPtr;\n"
"\t%scl->%s(",
c->mName.c_str(),
c->mName.c_str(),
(m->mRetType == "void")?"":"return ",
m->mFuncName.c_str());

for (i = 0; i < (signed)m->mParmName.size(); i++)
{
Expand All @@ -893,12 +832,6 @@ void emit_func(FILE * f, int aClass, int aMethod)
"}\n"
"\n");
}

if (initfunc)
{
emit_cppend(f);
fclose(f);
}
}


Expand Down
9 changes: 7 additions & 2 deletions src/tools/sanity/sanity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,14 @@ void testMisc()
int b = prg.rand();
CHECK(a == b);
a = 0;
int prev = prg.rand();
for (b = 0; b < 100; b++)
if (prg.rand() != prg.rand())
{
int next = prg.rand();
if (prev != next)
a = 1;
prev = next;
}
CHECK(a == 1);

soloud.deinit();
Expand Down Expand Up @@ -1552,7 +1557,7 @@ int main(int parc, char ** pars)
testFilters();
testCore();
testSpeech();
// testSpeedThings();
testSpeedThings();
// testMixer();
printf("\n%d tests, %d error(s) ", tests, errorcount);
if (!lastknownwrite && errorcount)
Expand Down
2 changes: 1 addition & 1 deletion src/tools/tedsid2zak/cbmtune.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ int CbmTune::parse(char *fName)
}
loadAddress = *((unsigned short *) (bufferPtr + dataIndex));
dataIndex += 2;
if (!playAddress) playAddress = 0; //loadAddress;
// if (!playAddress) playAddress = 0; //loadAddress;
return 0;
}

Expand Down
3 changes: 2 additions & 1 deletion src/tools/tedsid2zak/cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,9 @@ void CPU::process()
}
#endif
PC=(PC+1)&0xFFFF;
return;
}
else


switch (currins){
case 0xea : // NOP
Expand Down
4 changes: 2 additions & 2 deletions src/tools/tedsid2zak/sid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void SIDsound::setModel(unsigned int model)
(20163.0 - 1315.0) * x + 1315.0;
}
dcWave = 0x380;
dcMixer = -0xFFF*0xFF/18 >> 7;
dcMixer = -454; // gcc and msvc agree that "-0xFFF * 0xFF / 18 >> 7" turns into -454;
dcVoice = 0x800*0xFF;
break;

Expand All @@ -109,7 +109,7 @@ void SIDsound::setModel(unsigned int model)
* (18000.0 - 4600.0) + 4600.0;
}
dcWave = 0x380;
dcMixer = -0xFFF*0xFF/18 >> 7;
dcMixer = -454; // gcc and msvc agree that "-0xFFF * 0xFF / 18 >> 7" turns into -454;
dcVoice = 0x800*0xFF;
break;
}
Expand Down
Loading

0 comments on commit d72f30d

Please sign in to comment.