From 4186ca6cebb5efd5f794f6b3edbe945e65640133 Mon Sep 17 00:00:00 2001 From: elsid Date: Tue, 25 Nov 2025 00:02:27 +0100 Subject: [PATCH 1/2] Fix clang-analyzer-security.ArrayBound warning Size of an array is not a valid index. components/esm4/reader.cpp:925:15: error: Out of bound access to memory after the end of 'sGroupType' [clang-analyzer-security.ArrayBound,-warnings-as-errors] 925 | ss << sGroupType[std::min(type, std::size(sGroupType))]; // avoid out of range | ^ components/esm4/reader.cpp:627:13: note: Assuming field 'groupSize' is equal to field 'recHeaderSize' 627 | if (mCtx.recordHeader.group.groupSize == (std::uint32_t)mCtx.recHeaderSize) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ components/esm4/reader.cpp:627:9: note: Taking true branch 627 | if (mCtx.recordHeader.group.groupSize == (std::uint32_t)mCtx.recHeaderSize) | ^ components/esm4/reader.cpp:634:17: note: Assuming the condition is true 634 | if (!mCtx.groupStack.empty()) // top group may be empty (e.g. HAIR in Skyrim) | ^~~~~~~~~~~~~~~~~~~~~~~~ components/esm4/reader.cpp:634:13: note: Taking true branch 634 | if (!mCtx.groupStack.empty()) // top group may be empty (e.g. HAIR in Skyrim) | ^ components/esm4/reader.cpp:638:17: note: Calling 'Reader::exitGroupCheck' 638 | exitGroupCheck(); | ^~~~~~~~~~~~~~~~ components/esm4/reader.cpp:650:13: note: Assuming the condition is false 650 | if (mCtx.groupStack.empty()) | ^~~~~~~~~~~~~~~~~~~~~~~ components/esm4/reader.cpp:650:9: note: Taking false branch 650 | if (mCtx.groupStack.empty()) | ^ components/esm4/reader.cpp:655:16: note: Assuming 'lastGroupSize' is <= field 'second' 655 | while (mCtx.groupStack.back().second >= lastGroupSize) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ components/esm4/reader.cpp:655:9: note: Loop condition is true. Entering loop body 655 | while (mCtx.groupStack.back().second >= lastGroupSize) | ^ components/esm4/reader.cpp:663:17: note: Assuming 'overshoot' is <= 0 663 | if (overshoot > 0) | ^~~~~~~~~~~~~ components/esm4/reader.cpp:663:13: note: Taking false branch 663 | if (overshoot > 0) | ^ components/esm4/reader.cpp:676:17: note: Assuming the condition is false 676 | if (mCtx.groupStack.empty()) | ^~~~~~~~~~~~~~~~~~~~~~~ components/esm4/reader.cpp:676:13: note: Taking false branch 676 | if (mCtx.groupStack.empty()) | ^ components/esm4/reader.cpp:682:17: note: Assuming 'lastGroupSize' is >= field 'second' 682 | if (lastGroupSize < mCtx.groupStack.back().second) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ components/esm4/reader.cpp:682:13: note: Taking false branch 682 | if (lastGroupSize < mCtx.groupStack.back().second) | ^ components/esm4/reader.cpp:686:17: note: Assuming 'lastGroupSize' is < field 'second' 686 | if (mCtx.groupStack.back().second > lastGroupSize) // FIXME: debugging only | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ components/esm4/reader.cpp:686:13: note: Taking true branch 686 | if (mCtx.groupStack.back().second > lastGroupSize) // FIXME: debugging only | ^ components/esm4/reader.cpp:687:30: note: Calling 'printLabel' 687 | std::cerr << printLabel(mCtx.groupStack.back().first.label, mCtx.groupStack.back().first.type) | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ components/esm4/reader.cpp:925:15: note: Access of 'sGroupType' at index 12, while it holds only 12 'class std::basic_string_view' elements 925 | ss << sGroupType[std::min(type, std::size(sGroupType))]; // avoid out of range | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --- components/esm4/reader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/esm4/reader.cpp b/components/esm4/reader.cpp index 43a9e26418..93de160e5e 100644 --- a/components/esm4/reader.cpp +++ b/components/esm4/reader.cpp @@ -922,7 +922,7 @@ namespace ESM4 std::string printLabel(const GroupLabel& label, const std::uint32_t type) { std::ostringstream ss; - ss << sGroupType[std::min(type, std::size(sGroupType))]; // avoid out of range + ss << sGroupType[std::min(type, std::size(sGroupType) - 1)]; // avoid out of range switch (type) { From feb9cc004c7367d6207555a25ecc3749219a3d98 Mon Sep 17 00:00:00 2001 From: elsid Date: Tue, 25 Nov 2025 00:33:28 +0100 Subject: [PATCH 2/2] Fix portability-avoid-pragma-once warnings components/misc/helpviewer.hpp:1:1: error: avoid 'pragma once' directive; use include guards instead [portability-avoid-pragma-once,-warnings-as-errors] 1 | #pragma once | ^ apps/opencs/view/world/tableheadermouseeventhandler.hpp:1:1: error: avoid 'pragma once' directive; use include guards instead [portability-avoid-pragma-once,-warnings-as-errors] 1 | #pragma once | ^ --- apps/opencs/view/world/tableheadermouseeventhandler.hpp | 5 ++++- components/misc/helpviewer.hpp | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/apps/opencs/view/world/tableheadermouseeventhandler.hpp b/apps/opencs/view/world/tableheadermouseeventhandler.hpp index bef0b3389a..a5269747c7 100644 --- a/apps/opencs/view/world/tableheadermouseeventhandler.hpp +++ b/apps/opencs/view/world/tableheadermouseeventhandler.hpp @@ -1,4 +1,5 @@ -#pragma once +#ifndef OPENMW_APPS_OPENCS_VIEW_WORLD_TABLEHEADERMOUSEEVENTHANDLER_HPP +#define OPENMW_APPS_OPENCS_VIEW_WORLD_TABLEHEADERMOUSEEVENTHANDLER_HPP #include @@ -28,3 +29,5 @@ namespace CSVWorld }; // class TableHeaderMouseEventHandler } // namespace CSVWorld + +#endif diff --git a/components/misc/helpviewer.hpp b/components/misc/helpviewer.hpp index 0e6dad9637..42a2965c0b 100644 --- a/components/misc/helpviewer.hpp +++ b/components/misc/helpviewer.hpp @@ -1,4 +1,5 @@ -#pragma once +#ifndef OPENMW_COMPONENTS_MISC_HELPVIEWER_HPP +#define OPENMW_COMPONENTS_MISC_HELPVIEWER_HPP namespace Misc { @@ -7,3 +8,5 @@ namespace Misc void openHelp(const char* url); } } + +#endif