Skip to content

Commit 37d846d

Browse files
authored
fix: Miscellaneous warnings (#401)
* Some minor cleanup * Fix panic loggers * Disable runtime type information and exceptions * Fix more potential bus and warnings * Add C++ flags for C++ only * Fix some other warnings
1 parent 0af4346 commit 37d846d

File tree

10 files changed

+51
-33
lines changed

10 files changed

+51
-33
lines changed

include/Logging.h

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,23 @@ constexpr const char* openshockPathToFileName(const char (&path)[N]) {
6969

7070
#define OS_PANIC_PRINT(TAG, format, ...) OS_LOGE(TAG, "PANIC: " format, ##__VA_ARGS__)
7171

72-
#define OS_PANIC(TAG, format, ...) \
73-
OS_PANIC_PRINT(TAG, format ", restarting in 5 seconds...", ##__VA_ARGS__); \
74-
vTaskDelay(pdMS_TO_TICKS(5000)); \
75-
esp_restart()
76-
77-
#define OS_PANIC_OTA(TAG, format, ...) \
78-
OS_PANIC_PRINT(TAG, format ", invalidating update partition and restarting in 5 seconds...", ##__VA_ARGS__); \
79-
vTaskDelay(pdMS_TO_TICKS(5000)); \
80-
esp_ota_mark_app_invalid_rollback_and_reboot(); \
81-
esp_restart()
82-
83-
#define OS_PANIC_INSTANT(TAG, format, ...) \
84-
OS_PANIC_PRINT(TAG, format, ##__VA_ARGS__); \
85-
esp_restart()
72+
#define OS_PANIC(TAG, format, ...) \
73+
{ \
74+
OS_PANIC_PRINT(TAG, format ", restarting in 5 seconds...", ##__VA_ARGS__); \
75+
vTaskDelay(pdMS_TO_TICKS(5000)); \
76+
esp_restart(); \
77+
}
78+
79+
#define OS_PANIC_OTA(TAG, format, ...) \
80+
{ \
81+
OS_PANIC_PRINT(TAG, format ", invalidating update partition and restarting in 5 seconds...", ##__VA_ARGS__); \
82+
vTaskDelay(pdMS_TO_TICKS(5000)); \
83+
esp_ota_mark_app_invalid_rollback_and_reboot(); \
84+
esp_restart(); \
85+
}
86+
87+
#define OS_PANIC_INSTANT(TAG, format, ...) \
88+
{ \
89+
OS_PANIC_PRINT(TAG, format, ##__VA_ARGS__); \
90+
esp_restart(); \
91+
}

include/TinyVec.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

33
#include "Common.h"
4+
#include "Logging.h"
45

56
#include <cstdint>
67
#include <cstdlib>
@@ -69,10 +70,10 @@ class TinyVec {
6970
void reserve(SizeType new_cap)
7071
{
7172
if (new_cap <= _cap) return;
72-
if (sizeof(T) && new_cap > std::numeric_limits<SizeType>::max() / sizeof(T)) throw std::bad_alloc();
73+
if (sizeof(T) && new_cap > std::numeric_limits<SizeType>::max() / sizeof(T)) OS_PANIC_INSTANT("TVEC", "Cannot allocate a buffer of given size!");
7374

7475
void* newbuf = malloc(size_t(new_cap) * sizeof(T));
75-
if (!newbuf) throw std::bad_alloc();
76+
if (!newbuf) OS_PANIC_INSTANT("TVEC", "Could not allocate a buffer of given size!");
7677
if (_data) {
7778
memcpy(newbuf, _data, size_t(_len) * sizeof(T));
7879
free(_data);

include/radio/rmt/Sequence.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ namespace OpenShock::Rmt {
7373
m_size = 0;
7474
m_transmitEnd = 0;
7575
m_shockerId = 0;
76-
m_shockerModel = (ShockerModelType)0;
76+
m_shockerModel = static_cast<ShockerModelType>(0);
7777
}
7878

7979
rmt_data_t* m_data;

platformio.ini

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,20 @@ platform = espressif32 @ 6.12.0
1313
board = az-delivery-devkit-v4 ; Overridden per board
1414
framework = arduino
1515

16-
; Most warnings here are commented out because the compiler detects warnings outside own code, if we can disable external files for warnings that would be amazing!
1716
build_flags =
1817
-std=c++2a
1918
-std=gnu++2a
19+
-fno-exceptions
20+
-DCONFIG_ASYNC_TCP_QUEUE_SIZE=256
21+
build_unflags =
22+
-std=gnu++11
23+
24+
; Most warnings here are commented out because the compiler detects warnings outside own code, build_src_flags is meant to only be for our code but doesnt seem to work in this instance...
25+
build_src_flags =
2026
-Wall
2127
-Wextra
2228
;-Wpedantic
29+
;-Werror
2330
;-Wcast-align
2431
;-Wcast-qual
2532
;-Wctor-dtor-privacy
@@ -29,23 +36,21 @@ build_flags =
2936
-Wlogical-op
3037
;-Wmissing-declarations
3138
-Wmissing-include-dirs
32-
;-Wnoexcept
39+
-Wnoexcept
3340
;-Wold-style-cast
3441
;-Woverloaded-virtual
3542
;-Wredundant-decls
3643
;-Wshadow
3744
;-Wsign-conversion
38-
;-Wsign-promo
39-
;-Wstrict-null-sentinel
40-
;-Wstrict-overflow=5
45+
-Wsign-promo
46+
-Wstrict-null-sentinel
47+
-Wstrict-overflow=5
4148
-Wswitch-default
4249
;-Wundef
43-
;-Werror
4450
-Wno-unused
4551
-Wno-unknown-pragmas
46-
-DCONFIG_ASYNC_TCP_QUEUE_SIZE=256
47-
build_unflags =
48-
-std=gnu++11
52+
;-Weffc++
53+
4954
lib_deps =
5055
https://github.com/google/flatbuffers#8b02fe6178427b96aea25396b53ea4ae8cadd7d8
5156
https://github.com/OpenShock/ESPAsyncWebServer#469816c6bd287e3ecdda9e519c2532db019aa3c1

scripts/embed_env_vars.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,12 +245,12 @@ def print_dump(name: str, map: Mapping[str, str | int | bool]) -> None:
245245
cpp_defines = serialize_cpp_defines(cpp_defines)
246246

247247
print('Build type: ' + pio_build_type)
248-
print('Build defines: ' + str(cpp_defines))
249248

250249
# Set PIO variables.
251250
env['BUILD_TYPE'] = pio_build_type
252251
env['BUILD_FLAGS'] = remaining_build_flags
253252
env.Append(CPPDEFINES=list(cpp_defines.items()))
253+
env.Append(CXXFLAGS=['-fno-rtti', '-fno-threadsafe-statics', '-fno-use-cxa-atexit'])
254254

255255
# Rename the firmware.bin to app.bin.
256256
env.Replace(PROGNAME='app')

src/CommandHandler.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,10 @@ bool _internalSetKeepAliveEnabled(bool enabled)
134134
OS_LOGV(TAG, "Disabling keep-alive task");
135135
if (s_keepAliveTaskHandle != nullptr && s_keepAliveQueue != nullptr) {
136136
// Wait for the task to stop
137-
KnownShocker cmd {.killTask = true};
137+
KnownShocker cmd;
138+
memset(&cmd, 0, sizeof(cmd));
139+
cmd.killTask = true;
140+
138141
while (eTaskGetState(s_keepAliveTaskHandle) != eDeleted) {
139142
vTaskDelay(pdMS_TO_TICKS(10));
140143

src/GatewayConnectionManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ bool StartConnectingToLCG()
262262
return false;
263263
}
264264

265-
OS_LOGD(TAG, "Connecting to LCG endpoint { host: '%s', port: %hu, path: '%s' } in country %s", response.data.host.c_str(), response.data.port, response.data.path.c_str(), response.data.country.c_str());
265+
OS_LOGI(TAG, "Connecting to LCG endpoint { host: '%s', port: %hu, path: '%s' } in country %s", response.data.host.c_str(), response.data.port, response.data.path.c_str(), response.data.country.c_str());
266266
s_wsClient->connect(response.data.host, response.data.port, response.data.path);
267267

268268
return true;

src/radio/RFTransmitter.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,10 @@ void RFTransmitter::destroy()
122122
OS_LOGD(TAG, "[pin-%hhi] Stopping task", m_txPin);
123123

124124
// Wait for the task to stop
125-
Command cmd {.flags = kFlagDeleteTask};
125+
Command cmd;
126+
memset(&cmd, 0, sizeof(cmd));
127+
cmd.flags = kFlagDeleteTask;
128+
126129
while (eTaskGetState(m_taskHandle) != eDeleted) {
127130
vTaskDelay(pdMS_TO_TICKS(10));
128131

@@ -183,7 +186,7 @@ static void writeSequences(rmt_obj_t* rmt_handle, std::vector<Rmt::Sequence>& se
183186
rmtWriteBlocking(rmt_handle, seq->payload(), seq->size());
184187
} else {
185188
// Remove command if it has sent out its termination sequence for long enough
186-
if (timeToLive + kTerminatorDurationMs <= 0) {
189+
if (timeToLive <= -kTerminatorDurationMs) {
187190
seq = sequences.erase(seq);
188191
continue;
189192
}

src/serial/SerialInputHandler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const char* const TAG = "SerialInputHandler";
3333

3434
namespace std {
3535
struct hash_ci {
36-
std::size_t operator()(std::string_view str) const
36+
std::size_t operator()(std::string_view str) const noexcept
3737
{
3838
std::size_t hash = 7;
3939

src/serialization/JsonAPI.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ bool JsonAPI::ParseAssignLcgJsonResponse(int code, const cJSON* root, JsonAPI::A
245245
out = {};
246246

247247
out.host = host->valuestring;
248-
out.port = (uint16_t)portInt;
248+
out.port = static_cast<uint16_t>(portInt);
249249
out.path = path->valuestring;
250250
out.country = country->valuestring;
251251

0 commit comments

Comments
 (0)