Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid using memcpy to store timezone data #467

Merged
merged 1 commit into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/ArduinoIoTCloudThing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void ArduinoCloudThing::update() {
}

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

/* We have received a timezone update */
case TimezoneCommandDownId:
TimeService.setTimeZoneData(_command.timezoneCommandDown.params.offset,
_command.timezoneCommandDown.params.until);
TimeService.setTimeZoneData(_utcOffset, _utcOffsetExpireTime);
break;

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

_command.c.id = UnknownCmdId;
_command = UnknownCmdId;
_state = nextState;
}

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

void ArduinoCloudThing::handleMessage(Message* m) {
_command.c.id = UnknownCmdId;
_command = UnknownCmdId;
if (m != nullptr) {
memcpy(&_command, m, sizeof(CommandDown));
_command = m->id;
if (_command == TimezoneCommandDownId) {
_utcOffset = reinterpret_cast<TimezoneCommandDown*>(m)->params.offset;
_utcOffsetExpireTime = reinterpret_cast<TimezoneCommandDown*>(m)->params.until;
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/ArduinoIoTCloudThing.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class ArduinoCloudThing : public CloudProcess {
};

State _state;
CommandDown _command;
CommandId _command;
TimedAttempt _syncAttempt;
PropertyContainer _propertyContainer;
unsigned int _propertyContainerIndex;
Expand Down
Loading