From 810964f8e6b80fbfdb7f96b9a084acc4cbe5a3a1 Mon Sep 17 00:00:00 2001 From: Neil Date: Tue, 28 Sep 2021 12:08:09 +1000 Subject: Widen styleNumber in PositionCacheEntry from 8 to 16 bits to allow styles larger than 255 to be represented. Before this, it may have been possible but extremely rare for a cache entry to wrongly match a styled lexeme and produce incorrect layout. Using uint16_t from cstdint instead of a bit field as tools perform more checking on that. --- src/EditModel.cxx | 1 + src/EditView.cxx | 1 + src/Editor.cxx | 1 + src/MarginView.cxx | 1 + src/PositionCache.cxx | 7 ++++--- src/PositionCache.h | 10 +++++----- src/ScintillaBase.cxx | 1 + 7 files changed, 14 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/EditModel.cxx b/src/EditModel.cxx index 5dd3cc87d..db215d9aa 100644 --- a/src/EditModel.cxx +++ b/src/EditModel.cxx @@ -7,6 +7,7 @@ #include #include +#include #include #include #include diff --git a/src/EditView.cxx b/src/EditView.cxx index fb192abef..3ab4c17a5 100644 --- a/src/EditView.cxx +++ b/src/EditView.cxx @@ -7,6 +7,7 @@ #include #include +#include #include #include #include diff --git a/src/Editor.cxx b/src/Editor.cxx index 1559ece96..06d96134f 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -7,6 +7,7 @@ #include #include +#include #include #include #include diff --git a/src/MarginView.cxx b/src/MarginView.cxx index 41ab68b6c..d2aad0c39 100644 --- a/src/MarginView.cxx +++ b/src/MarginView.cxx @@ -7,6 +7,7 @@ #include #include +#include #include #include #include diff --git a/src/PositionCache.cxx b/src/PositionCache.cxx index d24b1ed8d..073a62692 100644 --- a/src/PositionCache.cxx +++ b/src/PositionCache.cxx @@ -7,6 +7,7 @@ #include #include +#include #include #include @@ -801,10 +802,10 @@ PositionCacheEntry::PositionCacheEntry(const PositionCacheEntry &other) : } void PositionCacheEntry::Set(unsigned int styleNumber_, std::string_view sv, - const XYPOSITION *positions_, unsigned int clock_) { + const XYPOSITION *positions_, uint16_t clock_) { Clear(); - styleNumber = styleNumber_; - len = static_cast(sv.length()); + styleNumber = static_cast(styleNumber_); + len = static_cast(sv.length()); clock = clock_; if (sv.data() && positions_) { positions = std::make_unique(len + (len / sizeof(XYPOSITION)) + 1); diff --git a/src/PositionCache.h b/src/PositionCache.h index 3dc68a0fd..79d63ee75 100644 --- a/src/PositionCache.h +++ b/src/PositionCache.h @@ -172,9 +172,9 @@ public: }; class PositionCacheEntry { - unsigned int styleNumber:8; - unsigned int len:8; - unsigned int clock:16; + uint16_t styleNumber; + uint16_t len; + uint16_t clock; std::unique_ptr positions; public: PositionCacheEntry() noexcept; @@ -185,7 +185,7 @@ public: void operator=(const PositionCacheEntry &) = delete; void operator=(PositionCacheEntry &&) = delete; ~PositionCacheEntry(); - void Set(unsigned int styleNumber_, std::string_view sv, const XYPOSITION *positions_, unsigned int clock_); + void Set(unsigned int styleNumber_, std::string_view sv, const XYPOSITION *positions_, uint16_t clock_); void Clear() noexcept; bool Retrieve(unsigned int styleNumber_, std::string_view sv, XYPOSITION *positions_) const noexcept; static size_t Hash(unsigned int styleNumber_, std::string_view sv) noexcept; @@ -273,7 +273,7 @@ public: class PositionCache { std::vector pces; - unsigned int clock; + uint16_t clock; bool allClear; public: PositionCache(); diff --git a/src/ScintillaBase.cxx b/src/ScintillaBase.cxx index b2a15a286..566a55a3c 100644 --- a/src/ScintillaBase.cxx +++ b/src/ScintillaBase.cxx @@ -7,6 +7,7 @@ #include #include +#include #include #include -- cgit v1.2.3