From 93379117422fe1cd1ba485caabe70b134a840ab2 Mon Sep 17 00:00:00 2001 From: Mateusz Jablonski Date: Mon, 2 Oct 2023 13:31:29 +0000 Subject: [PATCH] fix: add self-assign check in operator= Related-To: NEO-9038 Signed-off-by: Mateusz Jablonski --- level_zero/sysman/source/windows/sysman_kmd_sys.h | 6 ++++++ level_zero/tools/source/sysman/windows/kmd_sys.h | 6 ++++++ shared/source/kernel/kernel_arg_descriptor.h | 3 +++ shared/source/utilities/arrayref.h | 5 ++++- shared/source/utilities/const_stringref.h | 5 ++++- shared/source/utilities/windows/timer_util.cpp | 3 +++ 6 files changed, 26 insertions(+), 2 deletions(-) diff --git a/level_zero/sysman/source/windows/sysman_kmd_sys.h b/level_zero/sysman/source/windows/sysman_kmd_sys.h index 49136b2406..8e2b831784 100644 --- a/level_zero/sysman/source/windows/sysman_kmd_sys.h +++ b/level_zero/sysman/source/windows/sysman_kmd_sys.h @@ -518,6 +518,9 @@ struct RequestProperty { } } RequestProperty &operator=(const RequestProperty &other) { + if (this == &other) { + return *this; + } requestId = other.requestId; commandId = other.commandId; componentId = other.componentId; @@ -561,6 +564,9 @@ struct ResponseProperty { } } ResponseProperty &operator=(const ResponseProperty &other) { + if (this == &other) { + return *this; + } this->requestId = other.requestId; this->returnCode = other.returnCode; this->componentId = other.componentId; diff --git a/level_zero/tools/source/sysman/windows/kmd_sys.h b/level_zero/tools/source/sysman/windows/kmd_sys.h index 912cbd019c..bddfb53bac 100644 --- a/level_zero/tools/source/sysman/windows/kmd_sys.h +++ b/level_zero/tools/source/sysman/windows/kmd_sys.h @@ -518,6 +518,9 @@ struct RequestProperty { } } RequestProperty &operator=(const RequestProperty &other) { + if (this == &other) { + return *this; + } requestId = other.requestId; commandId = other.commandId; componentId = other.componentId; @@ -561,6 +564,9 @@ struct ResponseProperty { } } ResponseProperty &operator=(const ResponseProperty &other) { + if (this == &other) { + return *this; + } this->requestId = other.requestId; this->returnCode = other.returnCode; this->componentId = other.componentId; diff --git a/shared/source/kernel/kernel_arg_descriptor.h b/shared/source/kernel/kernel_arg_descriptor.h index 94c26152d3..dca0fa9576 100644 --- a/shared/source/kernel/kernel_arg_descriptor.h +++ b/shared/source/kernel/kernel_arg_descriptor.h @@ -305,6 +305,9 @@ inline bool patchPointer(ArrayRef buffer, const ArgDescPointer &arg, ui } inline ArgDescriptor &ArgDescriptor::operator=(const ArgDescriptor &rhs) { + if (this == &rhs) { + return *this; + } this->type = ArgTUnknown; switch (rhs.type) { default: diff --git a/shared/source/utilities/arrayref.h b/shared/source/utilities/arrayref.h index 1955babeb1..8f5ea68915 100644 --- a/shared/source/utilities/arrayref.h +++ b/shared/source/utilities/arrayref.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2022 Intel Corporation + * Copyright (C) 2018-2023 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -54,6 +54,9 @@ class ArrayRef { } ArrayRef &operator=(const ArrayRef &src) { + if (this == &src) { + return *this; + } this->begIt = src.begIt; this->endIt = src.endIt; return *this; diff --git a/shared/source/utilities/const_stringref.h b/shared/source/utilities/const_stringref.h index c5a3869b3b..091ef8106f 100644 --- a/shared/source/utilities/const_stringref.h +++ b/shared/source/utilities/const_stringref.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2022 Intel Corporation + * Copyright (C) 2019-2023 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -30,6 +30,9 @@ class ConstStringRef { } ConstStringRef &operator=(const ConstStringRef &rhs) { + if (this == &rhs) { + return *this; + } this->ptr = rhs.ptr; this->len = rhs.len; return *this; diff --git a/shared/source/utilities/windows/timer_util.cpp b/shared/source/utilities/windows/timer_util.cpp index 34403cdf8e..ea2edd64f8 100644 --- a/shared/source/utilities/windows/timer_util.cpp +++ b/shared/source/utilities/windows/timer_util.cpp @@ -53,6 +53,9 @@ class Timer::TimerImpl { } TimerImpl &operator=(const TimerImpl &t) { + if (this == &t) { + return *this; + } startTime = t.startTime; return *this; }