Skip to content

Commit 045b5f2

Browse files
authored
Merge pull request #25 from VeithMetro/development/pedantic-warnings
[Warnings] Adding pedantic warnings and treating warnings as errors, fixing warnings
2 parents 6252e0c + f76382d commit 045b5f2

File tree

7 files changed

+35
-12
lines changed

7 files changed

+35
-12
lines changed

CMakeLists.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,30 @@
1919
cmake_minimum_required(VERSION 3.3)
2020
project(Libraries)
2121

22+
find_package(WPEFramework)
23+
2224
if (BUILD_REFERENCE)
2325
add_definitions (-DBUILD_REFERENCE=${BUILD_REFERENCE})
2426
endif()
2527

28+
if(ENABLE_STRICT_COMPILER_SETTINGS)
29+
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
30+
message(FATAL_ERROR "Compiling with Clang")
31+
set(CMAKE_STRICT_COMPILER_SETTINGS "-Weverything -Wextra -Wpedantic -Werror")
32+
set(CMAKE_STRICT_CXX_COMPILER_SETTINGS "${CMAKE_STRICT_COMPILER_SETTINGS} -Wnon-virtual-dtor")
33+
elseif(${CMAKE_COMPILER_IS_GNUCXX})
34+
message(STATUS "Compiling with GCC")
35+
set(CMAKE_STRICT_COMPILER_SETTINGS "-Wall -Wextra -Wpedantic -Werror")
36+
set(CMAKE_STRICT_CXX_COMPILER_SETTINGS "${CMAKE_STRICT_COMPILER_SETTINGS} -Wnon-virtual-dtor")
37+
elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
38+
message(STATUS "Compiling with MS Visual Studio")
39+
set(CMAKE_STRICT_COMPILER_SETTINGS "/W4")
40+
else()
41+
message(STATUS "Compiler ${CMAKE_CXX_COMPILER_ID}")
42+
endif()
43+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_STRICT_CXX_COMPILER_SETTINGS}")
44+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_STRICT_COMPILER_SETTINGS}")
45+
endif()
46+
2647
add_subdirectory(Source)
2748

Source/bluetooth/BluetoothUtils.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,9 @@ int BtUtilsHciDevba(int dev_id, bdaddr_t* bdaddr)
113113

114114
int BtUtilsOtherBdaddr(int dd, int dev_id, long arg)
115115
{
116-
PUSH_WARNING(DISABLE_WARNING_MISSING_FIELD_INITIALIZERS)
117-
struct hci_dev_info di = { .dev_id = static_cast<uint16_t>(dev_id) };
118-
POP_WARNING()
116+
struct hci_dev_info di;
117+
di.dev_id = static_cast<uint16_t>(dev_id);
118+
119119
if (ioctl(dd, HCIGETDEVINFO, (void*)&di))
120120
return 0;
121121

@@ -127,9 +127,8 @@ POP_WARNING()
127127

128128
int BtUtilsSameBdaddr(int dd, int dev_id, long arg)
129129
{
130-
PUSH_WARNING(DISABLE_WARNING_MISSING_FIELD_INITIALIZERS)
131-
struct hci_dev_info di = { .dev_id = static_cast<uint16_t>(dev_id) };
132-
POP_WARNING()
130+
struct hci_dev_info di;
131+
di.dev_id = static_cast<uint16_t>(dev_id);
133132

134133
if (ioctl(dd, HCIGETDEVINFO, (void*)&di))
135134
return 0;

Source/bluetooth/HCISocket.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -813,8 +813,9 @@ namespace Bluetooth {
813813
// Create definitions for the HCI commands
814814
// ------------------------------------------------------------------------
815815
struct Command {
816+
PUSH_WARNING(DISABLE_WARNING_PEDANTIC)
816817
using Void = char[0];
817-
818+
POP_WARNING()
818819
typedef CommandType<cmd_opcode_pack(OGF_LINK_CTL, OCF_INQUIRY), inquiry_cp, uint8_t>
819820
Inquiry;
820821

Source/bluetooth/audio/AVDTPProfile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ namespace AVDTP {
455455
}
456456

457457
return (code);
458-
};
458+
}
459459

460460
} // namespace AVDTP
461461

Source/bluetooth/audio/SDPSocket.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ namespace SDP {
326326
uuid = Bluetooth::UUID((_buffer[_readerOffset] << 24) | (_buffer[_readerOffset + 1] << 16)
327327
| (_buffer[_readerOffset + 2] << 8) | _buffer[_readerOffset + 3]);
328328
} else {
329-
uint8_t buffer[size];
329+
uint8_t* buffer = static_cast<uint8_t*>(ALLOCA(size));
330330
uint8_t i = size;
331331
while (i-- > 0) {
332332
buffer[i] = _buffer[_readerOffset++];

Source/bluetooth/audio/codecs/SBC.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ ENUM_CONVERSION_BEGIN(Bluetooth::A2DP::SBC::preset)
3131
{ Bluetooth::A2DP::SBC::MQ, _TXT("MQ") },
3232
{ Bluetooth::A2DP::SBC::HQ, _TXT("HQ") },
3333
{ Bluetooth::A2DP::SBC::XQ, _TXT("XQ") },
34-
ENUM_CONVERSION_END(Bluetooth::A2DP::SBC::preset);
34+
ENUM_CONVERSION_END(Bluetooth::A2DP::SBC::preset)
3535

3636
ENUM_CONVERSION_BEGIN(Bluetooth::A2DP::SBC::Config::channelmode)
3737
{ Bluetooth::A2DP::SBC::Config::MONO, _TXT("Mono") },
3838
{ Bluetooth::A2DP::SBC::Config::STEREO, _TXT("Stereo") },
3939
{ Bluetooth::A2DP::SBC::Config::JOINT_STEREO, _TXT("JointSstereo") },
4040
{ Bluetooth::A2DP::SBC::Config::DUAL_CHANNEL, _TXT("DualChannel") },
41-
ENUM_CONVERSION_END(Bluetooth::A2DP::SBC::Config::channelmode);
41+
ENUM_CONVERSION_END(Bluetooth::A2DP::SBC::Config::channelmode)
4242

4343
namespace Bluetooth {
4444

Source/bluetooth/gatt/GATTSocket.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,9 @@ bool GATTSocket::Security(const uint8_t level)
324324
}
325325

326326
if (result == true) {
327-
struct bt_security btSecurity = { .level = level, 0 };
327+
struct bt_security btSecurity;
328+
btSecurity.level = level;
329+
btSecurity.key_size = 0;
328330
if (::setsockopt(Handle(), SOL_BLUETOOTH, BT_SECURITY, &btSecurity, sizeof(btSecurity)) != 0) {
329331
TRACE_L1("Failed to set Bluetooth Security level for device [%s], error: %d, try L2CAP Security", RemoteId().c_str(), errno);
330332
if (::setsockopt(Handle(), SOL_L2CAP, L2CAP_LM, &lm, sizeof(lm)) != 0) {

0 commit comments

Comments
 (0)