diff options
| -rw-r--r-- | CMakeLists.txt | 1 | ||||
| -rw-r--r-- | apt-pkg/cachefilter-patterns.h | 18 |
2 files changed, 18 insertions, 1 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index c4ea1660a..9d766c50d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -85,6 +85,7 @@ add_optional_compile_options(Wdouble-promotion) add_optional_compile_options(Wsuggest-override) add_optional_compile_options(Werror=suggest-override) add_optional_compile_options(Werror=return-type) +add_optional_compile_options(Wp,-D_GLIBCXX_ASSERTIONS) # apt-ftparchive dependencies find_package(Berkeley REQUIRED) if (BERKELEY_FOUND) diff --git a/apt-pkg/cachefilter-patterns.h b/apt-pkg/cachefilter-patterns.h index a45b9afcf..75784e040 100644 --- a/apt-pkg/cachefilter-patterns.h +++ b/apt-pkg/cachefilter-patterns.h @@ -78,7 +78,23 @@ struct APT_PUBLIC PatternTreeParser size_t offset = 0; }; - std::string_view sentence; + /// \brief Zero-terminated wrapper for std::string_view + /// + /// The code peeks a character ahead and assumes the input is zero-terminated, but it may not be, + /// this class provides a peek-ahead character access in operator[] by returning 0 for [size()]. + struct ZeroStringView : private std::string_view + { + explicit ZeroStringView(std::string_view s) : std::string_view(s) {} + char operator[](size_t i) + { + assert(i <= size()); + if (likely(i < size())) + return std::string_view::operator[](i); + return '\0'; + } + using std::string_view::size; + using std::string_view::substr; + } sentence; State state; PatternTreeParser(std::string_view sentence) : sentence(sentence){}; |
