Skip to content

Commit 98660f6

Browse files
committed
Fix 'maybe-uninitialized' warnings
Signed-off-by: Jacob Perron <jacobmperron@gmail.com>
1 parent 68ee257 commit 98660f6

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

examples/bumpers.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ int main(int argc, char** argv) {
6060
// Switch to Full mode
6161
robot.setMode(create::MODE_FULL);
6262

63-
uint16_t light_signals[6];
64-
bool light_bumpers[6];
65-
bool contact_bumpers[2];
63+
uint16_t light_signals[6] = {0, 0, 0, 0, 0, 0};
64+
bool light_bumpers[6] = {false, false, false, false, false, false};
65+
bool contact_bumpers[2] = {false, false};
6666

6767
while (true) {
6868
// Get light sensor data (only available for Create 2 or later robots)

src/create.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,16 @@ namespace create {
101101
// Get current time
102102
auto curTime = std::chrono::steady_clock::now();
103103
float dt = static_cast<std::chrono::duration<float>>(curTime - prevOnDataTime).count();
104-
float deltaDist, deltaX, deltaY, deltaYaw, leftWheelDist, rightWheelDist, wheelDistDiff;
104+
float deltaDist = 0.0f;
105+
float deltaX = 0.0f;
106+
float deltaY = 0.0f;
107+
float deltaYaw = 0.0f;
108+
float leftWheelDist = 0.0f;
109+
float rightWheelDist = 0.0f;
110+
float wheelDistDiff = 0.0f;
105111

106112
// Protocol versions 1 and 2 use distance and angle fields for odometry
107-
int16_t angleField;
113+
int16_t angleField = 0;
108114
if (model.getVersion() <= V_2) {
109115
// This is a standards compliant way of doing unsigned to signed conversion
110116
uint16_t distanceRaw = GET_DATA(ID_DISTANCE);
@@ -318,7 +324,7 @@ namespace create {
318324
// Switch to safe mode (required for compatibility with V_1)
319325
if (!(serial->sendOpcode(OC_START) && serial->sendOpcode(OC_CONTROL))) return false;
320326
}
321-
bool ret;
327+
bool ret = false;
322328
switch (mode) {
323329
case MODE_OFF:
324330
if (model.getVersion() == V_2) {

0 commit comments

Comments
 (0)