Skip to content

Commit 561def7

Browse files
author
Francois Best
authored
Merge pull request #81 from LnnrtS/fixedWarnings
fix: Implicit conversion & sign comparison compiler warnings - Increase warning level for sources - Fix implicit conversion & sign comparison warnings
2 parents 63caf9a + 33bd77d commit 561def7

File tree

4 files changed

+25
-8
lines changed

4 files changed

+25
-8
lines changed

builder/CMakeLists.txt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,26 @@ macro(setup_builder)
88

99
include_directories(${ROOT_SOURCE_DIR})
1010

11-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -W -Wshadow -Wunused-variable -Wunused-parameter -Wunused-function -Wunused -Wno-system-headers -Wno-deprecated -Woverloaded-virtual")
11+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \
12+
-Wall \
13+
-W \
14+
-Wshadow \
15+
-Wunused-variable \
16+
-Wunused-parameter \
17+
-Wunused-function \
18+
-Wunused \
19+
-Wno-system-headers \
20+
-Wno-deprecated \
21+
-Woverloaded-virtual \
22+
")
1223
if (BUILDER_ENABLE_PROFILING)
1324
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -O0")
1425
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} --coverage")
1526
endif()
1627
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
1728

1829
endmacro()
30+
31+
macro(increase_warning_level)
32+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wconversion -Wsign-conversion")
33+
endmacro()

src/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
increase_warning_level()
2+
13
project(midi)
24

35
add_library(midi STATIC

src/MIDI.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ unsigned decodeSysEx(const byte* inSysEx, byte* outData, unsigned inLength)
9595
else
9696
{
9797
const byte body = inSysEx[i];
98-
const byte msb = ((msbStorage >> byteIndex--) & 1) << 7;
98+
const byte msb = byte(((msbStorage >> byteIndex--) & 1) << 7);
9999
outData[count++] = msb | body;
100100
}
101101
}

src/MIDI.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ template<class SerialPort, class Settings>
292292
void MidiInterface<SerialPort, Settings>::sendPitchBend(int inPitchValue,
293293
Channel inChannel)
294294
{
295-
const unsigned bend = inPitchValue - MIDI_PITCHBEND_MIN;
295+
const unsigned bend = unsigned(inPitchValue - int(MIDI_PITCHBEND_MIN));
296296
send(PitchBend, (bend & 0x7f), (bend >> 7) & 0x7f, inChannel);
297297
}
298298

@@ -375,7 +375,7 @@ template<class SerialPort, class Settings>
375375
void MidiInterface<SerialPort, Settings>::sendTimeCodeQuarterFrame(DataByte inTypeNibble,
376376
DataByte inValuesNibble)
377377
{
378-
const byte data = (((inTypeNibble & 0x07) << 4) | (inValuesNibble & 0x0f));
378+
const byte data = byte((((inTypeNibble & 0x07) << 4) | (inValuesNibble & 0x0f)));
379379
sendTimeCodeQuarterFrame(data);
380380
}
381381

@@ -620,7 +620,7 @@ template<class SerialPort, class Settings>
620620
StatusByte MidiInterface<SerialPort, Settings>::getStatus(MidiType inType,
621621
Channel inChannel) const
622622
{
623-
return ((byte)inType | ((inChannel - 1) & 0x0f));
623+
return StatusByte(((byte)inType | ((inChannel - 1) & 0x0f)));
624624
}
625625

626626
// -----------------------------------------------------------------------------
@@ -856,7 +856,7 @@ bool MidiInterface<SerialPort, Settings>::parse()
856856

857857
// Get length
858858
mMessage.data1 = mPendingMessageIndex & 0xff; // LSB
859-
mMessage.data2 = mPendingMessageIndex >> 8; // MSB
859+
mMessage.data2 = byte(mPendingMessageIndex >> 8); // MSB
860860
mMessage.channel = 0;
861861
mMessage.valid = true;
862862

@@ -1116,7 +1116,7 @@ MidiType MidiInterface<SerialPort, Settings>::getTypeFromStatusByte(byte inStatu
11161116
template<class SerialPort, class Settings>
11171117
inline Channel MidiInterface<SerialPort, Settings>::getChannelFromStatusByte(byte inStatus)
11181118
{
1119-
return (inStatus & 0x0f) + 1;
1119+
return Channel((inStatus & 0x0f) + 1);
11201120
}
11211121

11221122
template<class SerialPort, class Settings>
@@ -1221,7 +1221,7 @@ void MidiInterface<SerialPort, Settings>::launchCallback()
12211221

12221222
// Occasional messages
12231223
case TimeCodeQuarterFrame: if (mTimeCodeQuarterFrameCallback != 0) mTimeCodeQuarterFrameCallback(mMessage.data1); break;
1224-
case SongPosition: if (mSongPositionCallback != 0) mSongPositionCallback((mMessage.data1 & 0x7f) | ((mMessage.data2 & 0x7f) << 7)); break;
1224+
case SongPosition: if (mSongPositionCallback != 0) mSongPositionCallback(unsigned((mMessage.data1 & 0x7f) | ((mMessage.data2 & 0x7f) << 7))); break;
12251225
case SongSelect: if (mSongSelectCallback != 0) mSongSelectCallback(mMessage.data1); break;
12261226
case TuneRequest: if (mTuneRequestCallback != 0) mTuneRequestCallback(); break;
12271227

0 commit comments

Comments
 (0)