Skip to content

Commit 4e13d23

Browse files
[SYCL][NFCI] Address static analyzer concerns (#16296)
Two changes were made: Special `padding` field in accessors is now zero-initialized. We construct a `host_accessor` object in our stream implementation and static analyzer complained that some of the accessor's fields were uninitialized. It is not like we even reference `padding` field from anywhere, but the code change seems small, so I decided to add the initializer. Fixed a condition to prevent access to an array of `N` elements at index `N`, which is outside of the array because they are 0-indexed. --------- Co-authored-by: Marcos Maronas <[email protected]>
1 parent f26c0b8 commit 4e13d23

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

sycl/include/sycl/accessor.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,7 @@ class __SYCL_EBO __SYCL_SPECIAL_CLASS __SYCL_TYPE(accessor) accessor :
807807

808808
char padding[sizeof(detail::AccessorImplDevice<AdjustedDim>) +
809809
sizeof(PtrType) - sizeof(detail::AccessorBaseHost) -
810-
sizeof(MAccData)];
810+
sizeof(MAccData)] = {0};
811811

812812
PtrType getQualifiedPtr() const noexcept {
813813
if constexpr (IsHostBuf)
@@ -2192,7 +2192,7 @@ class __SYCL_SPECIAL_CLASS local_accessor_base :
21922192
: detail::LocalAccessorBaseHost{Impl} {}
21932193

21942194
char padding[sizeof(detail::LocalAccessorBaseDevice<AdjustedDim>) +
2195-
sizeof(PtrType) - sizeof(detail::LocalAccessorBaseHost)];
2195+
sizeof(PtrType) - sizeof(detail::LocalAccessorBaseHost)] = {0};
21962196
using detail::LocalAccessorBaseHost::getSize;
21972197

21982198
PtrType getQualifiedPtr() const {

sycl/source/detail/config.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ void readConfig(bool ForceInitialization) {
106106
// Finding the position of '='
107107
Position = BufString.find("=");
108108
// Checking that the variable name is less than MAX_CONFIG_NAME and more
109-
// than zero character
110-
if ((Position <= MAX_CONFIG_NAME) && (Position > 0)) {
109+
// than zero characters.
110+
if ((Position < MAX_CONFIG_NAME) && (Position > 0)) {
111111
// Checking that the value is less than MAX_CONFIG_VALUE and
112112
// more than zero character
113113
if ((BufString.length() - (Position + 1) <= MAX_CONFIG_VALUE) &&

0 commit comments

Comments
 (0)