Skip to content

Commit 06613dd

Browse files
authored
Merge pull request #467 from pennam/message-fix
Avoid using memcpy to store timezone data
2 parents 335daf8 + 3069915 commit 06613dd

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

Diff for: src/ArduinoIoTCloudThing.cpp

+9-6
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ void ArduinoCloudThing::update() {
6969
}
7070

7171
/* Handle external events */
72-
switch (_command.c.id) {
72+
switch (_command) {
7373
case LastValuesUpdateCmdId:
7474
if (_state == State::RequestLastValues) {
7575
DEBUG_VERBOSE("CloudThing::%s Thing is synced", __FUNCTION__);
@@ -79,8 +79,7 @@ void ArduinoCloudThing::update() {
7979

8080
/* We have received a timezone update */
8181
case TimezoneCommandDownId:
82-
TimeService.setTimeZoneData(_command.timezoneCommandDown.params.offset,
83-
_command.timezoneCommandDown.params.until);
82+
TimeService.setTimeZoneData(_utcOffset, _utcOffsetExpireTime);
8483
break;
8584

8685
/* We have received a reset command */
@@ -92,7 +91,7 @@ void ArduinoCloudThing::update() {
9291
break;
9392
}
9493

95-
_command.c.id = UnknownCmdId;
94+
_command = UnknownCmdId;
9695
_state = nextState;
9796
}
9897

@@ -101,9 +100,13 @@ int ArduinoCloudThing::connected() {
101100
}
102101

103102
void ArduinoCloudThing::handleMessage(Message* m) {
104-
_command.c.id = UnknownCmdId;
103+
_command = UnknownCmdId;
105104
if (m != nullptr) {
106-
memcpy(&_command, m, sizeof(CommandDown));
105+
_command = m->id;
106+
if (_command == TimezoneCommandDownId) {
107+
_utcOffset = reinterpret_cast<TimezoneCommandDown*>(m)->params.offset;
108+
_utcOffsetExpireTime = reinterpret_cast<TimezoneCommandDown*>(m)->params.until;
109+
}
107110
}
108111
}
109112

Diff for: src/ArduinoIoTCloudThing.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class ArduinoCloudThing : public CloudProcess {
5151
};
5252

5353
State _state;
54-
CommandDown _command;
54+
CommandId _command;
5555
TimedAttempt _syncAttempt;
5656
PropertyContainer _propertyContainer;
5757
unsigned int _propertyContainerIndex;

0 commit comments

Comments
 (0)