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 3710cf1
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
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_);
if (elapsed < this->updateDelay_) {
delay(this->updateDelay_ - elapsed);
}
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
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 || n >= buffer_size - written) {

Check failure on line 458 in lib/opengloves/senseshift/opengloves/autoconfig.hpp

View workflow job for this annotation

GitHub Actions / Build opengloves_lucidgloves_proto4_ffb with coverage, -D OPENGLOVES_COMMUNICATION=OPENGLOVES_COMM_BLESERIAL -D CALIBRATION_CURL="new ::SenseShift::Input::Calibration::FixedCenterPointDeviationCalibrator<float>(0.66F, 0.005F)"

'buffer_size' was not declared in this scope

Check failure on line 458 in lib/opengloves/senseshift/opengloves/autoconfig.hpp

View workflow job for this annotation

GitHub Actions / Build opengloves_lucidgloves_proto4_ffb with coverage, -D OPENGLOVES_COMMUNICATION=OPENGLOVES_COMM_BLESERIAL -D CALIBRATION_CURL="new ::SenseShift::Input::Calibration::FixedCenterPointDeviationCalibrator<float>(0.66F, 0.005F)"

'written' was not declared in this scope; did you mean 'write'?

Check failure on line 458 in lib/opengloves/senseshift/opengloves/autoconfig.hpp

View workflow job for this annotation

GitHub Actions / Build opengloves_lucidgloves_proto4_ffb with coverage, -D OPENGLOVES_COMMUNICATION=OPENGLOVES_COMM_BTSERIAL -D CALIBRATION_CURL="new ::SenseShift::Input::Calibration::CenterPointDeviationCalibrator<float>(0.66F, 0.005F)"

'buffer_size' was not declared in this scope

Check failure on line 458 in lib/opengloves/senseshift/opengloves/autoconfig.hpp

View workflow job for this annotation

GitHub Actions / Build opengloves_lucidgloves_proto4_ffb with coverage, -D OPENGLOVES_COMMUNICATION=OPENGLOVES_COMM_BTSERIAL -D CALIBRATION_CURL="new ::SenseShift::Input::Calibration::CenterPointDeviationCalibrator<float>(0.66F, 0.005F)"

'written' was not declared in this scope; did you mean 'write'?

Check failure on line 458 in lib/opengloves/senseshift/opengloves/autoconfig.hpp

View workflow job for this annotation

GitHub Actions / Build opengloves_lucidgloves_proto4_ffb without coverage, -D OPENGLOVES_COMMUNICATION=OPENGLOVES_COMM_BTSERIAL -D

'buffer_size' was not declared in this scope

Check failure on line 458 in lib/opengloves/senseshift/opengloves/autoconfig.hpp

View workflow job for this annotation

GitHub Actions / Build opengloves_lucidgloves_proto4_ffb without coverage, -D OPENGLOVES_COMMUNICATION=OPENGLOVES_COMM_BTSERIAL -D

'written' was not declared in this scope; did you mean 'write'?

Check failure on line 458 in lib/opengloves/senseshift/opengloves/autoconfig.hpp

View workflow job for this annotation

GitHub Actions / Build opengloves_lucidgloves_proto4_ffb without coverage, -D OPENGLOVES_COMMUNICATION=OPENGLOVES_COMM_BLESERIAL -D

'buffer_size' was not declared in this scope

Check failure on line 458 in lib/opengloves/senseshift/opengloves/autoconfig.hpp

View workflow job for this annotation

GitHub Actions / Build opengloves_lucidgloves_proto4_ffb without coverage, -D OPENGLOVES_COMMUNICATION=OPENGLOVES_COMM_BLESERIAL -D

'written' was not declared in this scope; did you mean 'write'?
log_e("Failed to generate Bluetooth name");
} else {
suffix[4] = '\0';
name = BTSERIAL_PREFIX + std::string(suffix, 4);
}

log_i("Generated Bluetooth name: %s", name.c_str());
#endif
Expand Down

0 comments on commit 3710cf1

Please sign in to comment.