From 4de31ccc9ef47e7b16330d226d071d5d006faa6d Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Sat, 7 Mar 2020 22:02:35 +0200 Subject: libcamera: controls: Fix strict aliasing violation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit gcc 8.3.0 for ARM complains about strict aliasing violations: ../../src/libcamera/controls.cpp: In member function ‘void libcamera::ControlValue::release()’: ../../src/libcamera/controls.cpp:111:13: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing] delete[] *reinterpret_cast(&storage_); Fix it and simplify the code at the same time. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- src/libcamera/controls.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'src/libcamera/controls.cpp') diff --git a/src/libcamera/controls.cpp b/src/libcamera/controls.cpp index 94bdbdd9..4326174a 100644 --- a/src/libcamera/controls.cpp +++ b/src/libcamera/controls.cpp @@ -107,9 +107,9 @@ void ControlValue::release() { std::size_t size = numElements_ * ControlValueSize[type_]; - if (size > sizeof(storage_)) { - delete[] *reinterpret_cast(&storage_); - storage_ = 0; + if (size > sizeof(value_)) { + delete[] reinterpret_cast(storage_); + storage_ = nullptr; } } @@ -176,9 +176,9 @@ ControlValue &ControlValue::operator=(const ControlValue &other) Span ControlValue::data() const { std::size_t size = numElements_ * ControlValueSize[type_]; - const uint8_t *data = size > sizeof(storage_) - ? *reinterpret_cast(&storage_) - : reinterpret_cast(&storage_); + const uint8_t *data = size > sizeof(value_) + ? reinterpret_cast(storage_) + : reinterpret_cast(&value_); return { data, size }; } @@ -308,11 +308,11 @@ void ControlValue::set(ControlType type, bool isArray, const void *data, std::size_t size = elementSize * numElements; void *storage; - if (size > sizeof(storage_)) { - storage = reinterpret_cast(new char[size]); - *reinterpret_cast(&storage_) = storage; + if (size > sizeof(value_)) { + storage_ = reinterpret_cast(new uint8_t[size]); + storage = storage_; } else { - storage = reinterpret_cast(&storage_); + storage = reinterpret_cast(&value_); } memcpy(storage, data, size); -- cgit v1.2.1