Skip to content

Commit

Permalink
fix: resolve compiler warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
leon0399 committed Aug 9, 2024
1 parent 3465d35 commit ea1eab1
Show file tree
Hide file tree
Showing 19 changed files with 42 additions and 28 deletions.
2 changes: 1 addition & 1 deletion docs/DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Function argument: `snake_case`
### Fix `clang-format`

```shell
find lib include firmware test examples -type f -regex '.*\.\(cpp\|hpp\|cu\|c\|h\)' ! -regex '^lib/frozen\(/.*\)' -exec clang-format-16 -style=file -i {} \;
find lib include firmware test examples variants -type f -regex '.*\.\(cpp\|hpp\|cu\|c\|h\)' -exec clang-format-16 -style=file -i {} \;
```

# Debugging
Expand Down
8 changes: 4 additions & 4 deletions lib/bhaptics/senseshift/bh/encoding.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Decoder {
FloatBody* output,
const std::array<std::uint8_t, N>& value,
const std::array<OutputLayout, N>& layout,
const Effect effect
const Effect
)
{
for (size_t i = 0; i < N; i++) {
Expand Down Expand Up @@ -59,7 +59,7 @@ class Decoder {
FloatBody* output,
const std::array<std::uint8_t, N>& value,
const std::array<Position, N>& layout,
const Effect effect,
const Effect,
const Target target
)
{
Expand Down Expand Up @@ -137,7 +137,7 @@ class Decoder {
std::array<std::uint8_t, VEST_LAYOUT_SIZE> result{};

// Unpack values
for (auto i = 0; i < VEST_PAYLOAD_SIZE; i++) {
for (size_t i = 0; i < VEST_PAYLOAD_SIZE; i++) {
const std::uint8_t byte = value[i];
const size_t actIndex = i * 2;

Expand All @@ -146,7 +146,7 @@ class Decoder {
}

// Assign max value into each group
for (auto i = 0; i < N; i++) {
for (size_t i = 0; i < N; i++) {
auto groupIndex = layoutGroups[i];

if (groupIndex % 10 >= 4) {
Expand Down
3 changes: 1 addition & 2 deletions lib/freertos/senseshift/freertos/task.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ class ComponentUpdateTask : public Task<ComponentUpdateTask<Tp>> {
[[noreturn]] void run()
{
auto now = millis();
auto targetHz = 1000 / this->updateDelay_;

while (true) {
now = millis();
Expand All @@ -151,7 +150,7 @@ class ComponentUpdateTask : public Task<ComponentUpdateTask<Tp>> {

const auto elapsed = millis() - now;

log_d("T: %d, Fmax: %dHz, Ft: %dHz", elapsed, 1000 / elapsed, targetHz);
log_d("T: %d, Fmax: %dHz, Ft: %dHz", elapsed, 1000 / elapsed, 1000 / this->updateDelay_);

Check warning on line 153 in lib/freertos/senseshift/freertos/task.hpp

View check run for this annotation

Codecov / codecov/patch

lib/freertos/senseshift/freertos/task.hpp#L153

Added line #L153 was not covered by tests
if (elapsed < this->updateDelay_) {
delay(this->updateDelay_ - elapsed);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/io/senseshift/input/calibration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ class FixedCenterPointDeviationCalibrator : public ICalibrator<Tp> {
void reset() override
{
}
void update(ValueType input) override
void update(ValueType) override
{
}

Expand Down
9 changes: 5 additions & 4 deletions lib/io/senseshift/input/filter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,9 @@ class ExponentialMovingAverageFilter : public IFilter<Tp> {

/// Deadzone filter. Clamps acc_ to center if it is within the deadzone.
/// Usually used to filter out noise in the joystick.
class CenterDeadzoneFilter : public IFilter<float> {
class SinglePointDeadzoneFilter : public IFilter<float> {
public:
explicit CenterDeadzoneFilter(float deadzone, float center = 0.5F) : deadzone_(deadzone), center_(center){};
explicit SinglePointDeadzoneFilter(float deadzone, float center = 0.5F) : deadzone_(deadzone), center_(center){};

inline auto filter(ISimpleSensor<float>* /*sensor*/, float value) -> float override
{
Expand All @@ -270,11 +270,12 @@ class CenterDeadzoneFilter : public IFilter<float> {
}

private:
const float deadzone_;
const float center_;

float deadzone_;
};

using CenterDeadzoneFilter = SinglePointDeadzoneFilter;

/// Interpolates the value from the lookup table.
/// Can be used to determine battery level from the voltage.
///
Expand Down
2 changes: 1 addition & 1 deletion lib/io/senseshift/input/sensor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class SimpleSensorDecorator : public Sensor<Tp> {
using ValueType = Tp;
using SourceType = ISimpleSensor<ValueType>;

explicit SimpleSensorDecorator(SourceType* source) : source_(source), Sensor<Tp>()
explicit SimpleSensorDecorator(SourceType* source) : Sensor<Tp>(), source_(source)
{
}

Expand Down
2 changes: 1 addition & 1 deletion lib/io/senseshift/input/sensor/analog_threshold.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ class AnalogThresholdSensor : public BinarySensor {
Sensor<Tp>* source, Tp threshold_upper, Tp threshold_lower, bool attach_callbacks = false
) :
source_(source),
threshold_upper_(threshold_upper),
threshold_lower_(threshold_lower),
threshold_upper_(threshold_upper),
attach_callbacks_(attach_callbacks)
{
}
Expand Down
9 changes: 9 additions & 0 deletions lib/math/senseshift/math/point2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ struct Point2 {
{
}

constexpr auto operator=(const Point2<Tp>& v) -> Point2&
{
if (this != &v) {
x = v.x;
y = v.y;
}
return *this;
}

constexpr inline auto operator==(const Point2<Tp>& rhs) const -> bool
{
return x == rhs.x && y == rhs.y;
Expand Down
11 changes: 8 additions & 3 deletions lib/opengloves/senseshift/opengloves/autoconfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,9 +453,14 @@ auto createTransport() -> ITransport*
#ifdef BTSERIAL_NAME
name = BTSERIAL_NAME;
#else
char suffix[4];
snprintf(suffix, 4, "%04X", (uint16_t) (ESP.getEfuseMac() >> 32));
name = BTSERIAL_PREFIX + std::string(suffix);
char suffix[5];

Check notice

Code scanning / Flawfinder

Statically-sized arrays can be improperly restricted, leading to potential overflows or other issues (CWE-119!/CWE-120). Note

buffer/char:Statically-sized arrays can be improperly restricted, leading to potential overflows or other issues (CWE-119!/CWE-120).
int n = snprintf(suffix, 5, "%04X", (uint16_t) (ESP.getEfuseMac() >> 32));

Check notice

Code scanning / Flawfinder

If format strings can be influenced by an attacker, they can be exploited, and note that sprintf variations do not always \0-terminate (CWE-134). Note

format/snprintf:If format strings can be influenced by an attacker, they can be exploited, and note that sprintf variations do not always \0-terminate (CWE-134).
if (n < 0) {
log_e("Failed to generate Bluetooth name");

Check warning on line 459 in lib/opengloves/senseshift/opengloves/autoconfig.hpp

View check run for this annotation

Codecov / codecov/patch

lib/opengloves/senseshift/opengloves/autoconfig.hpp#L456-L459

Added lines #L456 - L459 were not covered by tests
} else {
suffix[4] = '\0';
name = BTSERIAL_PREFIX + std::string(suffix, 4);

Check warning on line 462 in lib/opengloves/senseshift/opengloves/autoconfig.hpp

View check run for this annotation

Codecov / codecov/patch

lib/opengloves/senseshift/opengloves/autoconfig.hpp#L461-L462

Added lines #L461 - L462 were not covered by tests
}

log_i("Generated Bluetooth name: %s", name.c_str());
#endif
Expand Down
2 changes: 1 addition & 1 deletion test/test_battery/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void loop(void)

#else

int main(int argc, char** argv)
int main()
{
return process();
}
Expand Down
2 changes: 1 addition & 1 deletion test/test_bhaptics_encoding/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ void loop(void)

#else

int main(int argc, char** argv)
int main()
{
return process();
}
Expand Down
2 changes: 1 addition & 1 deletion test/test_body_gestures/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ void loop(void)

#else

int main(int argc, char** argv)
int main()
{
return process();
}
Expand Down
2 changes: 1 addition & 1 deletion test/test_core_helpers/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ void loop(void)

#else

int main(int argc, char** argv)
int main()
{
return process();
}
Expand Down
2 changes: 1 addition & 1 deletion test/test_haptics_body/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void loop(void)

#else

int main(int argc, char** argv)
int main()
{
return process();
}
Expand Down
2 changes: 1 addition & 1 deletion test/test_haptics_plane/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ void loop(void)

#else

int main(int argc, char** argv)
int main()
{
return process();
}
Expand Down
2 changes: 1 addition & 1 deletion test/test_io_calibration/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ void loop(void)

#else

int main(int argc, char** argv)
int main()
{
return process();
}
Expand Down
2 changes: 1 addition & 1 deletion test/test_io_filter/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ void loop(void)

#else

int main(int argc, char** argv)
int main()
{
return process();
}
Expand Down
4 changes: 2 additions & 2 deletions test/test_io_sensor/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class DummyCalibrator : public ::SenseShift::Input::Calibration::ICalibrator<flo
{
this->calibrated = input;
}
float calibrate(float input) const override
float calibrate(float) const override
{
return calibrated;
}
Expand Down Expand Up @@ -264,7 +264,7 @@ void loop(void)

#else

int main(int argc, char** argv)
int main()
{
return process();
}
Expand Down
2 changes: 1 addition & 1 deletion test/test_math_point2/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void loop(void)

#else

int main(int argc, char** argv)
int main()
{
return process();
}
Expand Down

0 comments on commit ea1eab1

Please sign in to comment.