From: <man...@us...> - 2013-12-07 03:36:05
|
Revision: 3398 http://sourceforge.net/p/modplug/code/3398 Author: manxorist Date: 2013-12-07 03:35:55 +0000 (Sat, 07 Dec 2013) Log Message: ----------- [Ref] Silence GCC type-range warnings in IsSpecialNote(). [Ref] 2 tiny related cleanups. Modified Paths: -------------- trunk/OpenMPT/common/misc_util.h trunk/OpenMPT/soundlib/Sndfile.cpp trunk/OpenMPT/soundlib/mod_specifications.cpp trunk/OpenMPT/soundlib/modcommand.h Modified: trunk/OpenMPT/common/misc_util.h =================================================================== --- trunk/OpenMPT/common/misc_util.h 2013-12-07 01:56:14 UTC (rev 3397) +++ trunk/OpenMPT/common/misc_util.h 2013-12-07 03:35:55 UTC (rev 3398) @@ -275,6 +275,15 @@ else return val; } +// Check if val is in [lo,hi] without causing compiler warnings +// if theses checks are always true due to the domain of T. +// GCC does not warn if the type is templated. +template<typename T, typename C> +inline bool IsInRange(T val, C lo, C hi) +//-------------------------------------- +{ + return lo <= val && val <= hi; +} // Like Limit, but with upperlimit only. template<class T, class C> Modified: trunk/OpenMPT/soundlib/Sndfile.cpp =================================================================== --- trunk/OpenMPT/soundlib/Sndfile.cpp 2013-12-07 01:56:14 UTC (rev 3397) +++ trunk/OpenMPT/soundlib/Sndfile.cpp 2013-12-07 03:35:55 UTC (rev 3398) @@ -1561,7 +1561,7 @@ { if(p->IsNote()) { - if ((p->instr) && (p->instr < MAX_INSTRUMENTS)) + if ((p->instr) && (IsInRange(p->instr, (INSTRUMENTINDEX)0, MAX_INSTRUMENTS))) { ModInstrument *pIns = Instruments[p->instr]; if (pIns) Modified: trunk/OpenMPT/soundlib/mod_specifications.cpp =================================================================== --- trunk/OpenMPT/soundlib/mod_specifications.cpp 2013-12-07 01:56:14 UTC (rev 3397) +++ trunk/OpenMPT/soundlib/mod_specifications.cpp 2013-12-07 03:35:55 UTC (rev 3398) @@ -402,7 +402,7 @@ { if(note >= noteMin && note <= noteMax) return true; - else if(note >= NOTE_MIN_SPECIAL && note <= NOTE_MAX_SPECIAL) + else if(ModCommand::IsSpecialNote(note)) { if(note == NOTE_NOTECUT) return hasNoteCut; Modified: trunk/OpenMPT/soundlib/modcommand.h =================================================================== --- trunk/OpenMPT/soundlib/modcommand.h 2013-12-07 01:56:14 UTC (rev 3397) +++ trunk/OpenMPT/soundlib/modcommand.h 2013-12-07 03:35:55 UTC (rev 3398) @@ -12,6 +12,8 @@ #include "Snd_defs.h" +#include "../common/misc_util.h" + #include <cstring> // Note definitions @@ -154,8 +156,8 @@ bool IsNote() const { return note >= NOTE_MIN && note <= NOTE_MAX; } static bool IsNote(NOTE note) { return note >= NOTE_MIN && note <= NOTE_MAX; } // Returns true if and only if note is a valid special note. - bool IsSpecialNote() const { return note >= NOTE_MIN_SPECIAL && note <= NOTE_MAX_SPECIAL; } - static bool IsSpecialNote(NOTE note) { return note >= NOTE_MIN_SPECIAL && note <= NOTE_MAX_SPECIAL; } + bool IsSpecialNote() const { return IsInRange(note, NOTE_MIN_SPECIAL, NOTE_MAX_SPECIAL); } + static bool IsSpecialNote(NOTE note) { return IsInRange(note, NOTE_MIN_SPECIAL, NOTE_MAX_SPECIAL); } // Returns true if and only if note is a valid musical note or the note entry is empty. bool IsNoteOrEmpty() const { return note == NOTE_NONE || IsNote(); } static bool IsNoteOrEmpty(NOTE note) { return note == NOTE_NONE || IsNote(note); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |