-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix CHIPDeviceCallbacksMgr callback info storage (#7842)
The code in CHIPDeviceCallbacksMgr is storing information about each registered callback in some inline space reserved for this purpose. However, the space consists of two separate scalar fields (mInfoPtr and mInfoScalar). Type punning these fields as a struct is undefined behavior in C++. In fact these structures do not even fit on 32 bit platforms without relying on padding that's added between the fields. GCC can diagnose the invalid casts used here and issues the following diagnostic (unless strict aliasing is disabled, which it is currently in all builds except ESP32): ../third_party/connectedhomeip/src/app/util/CHIPDeviceCallbacksMgr.h: In instantiation of 'CHIP_ERROR chip::app::CHIPDeviceCallbacksMgr::GetCallback(T&, chip::Callback::CallbackDeque&, chip::Callback::Cancelable**) [with T = {anonymous}::ReportCallbackInfo; CHIP_ERROR = int]': ../third_party/connectedhomeip/src/app/util/CHIPDeviceCallbacksMgr.cpp:123:5: required from here ../third_party/connectedhomeip/src/app/util/CHIPDeviceCallbacksMgr.h:84:52: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] Use a character array instead and add a static_assert that the data fits. Placing structures in character arrays is legal as C++ has an explicit carve-out for this case.
- Loading branch information
Showing
8 changed files
with
517 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Copyright (c) 2021 Project CHIP Authors | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import("//build_overrides/chip.gni") | ||
|
||
source_set("device_callbacks_manager") { | ||
sources = [ | ||
"CHIPDeviceCallbacksMgr.cpp", | ||
"CHIPDeviceCallbacksMgr.h", | ||
] | ||
|
||
public_deps = [ | ||
"${chip_root}/src/lib/core", | ||
"${chip_root}/src/lib/support", | ||
] | ||
|
||
cflags = [ "-Wconversion" ] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters