From 55da426d44a14271457ae14c61e673b2c9ddc6fa Mon Sep 17 00:00:00 2001 From: frosch Date: Sun, 17 Sep 2023 00:33:35 +0200 Subject: [PATCH] Codechange: All ParagraphLayoutFactory::AppendToBuffer assume that the buffer has at least some space. Assert on that. --- src/gfx_layout_fallback.cpp | 3 ++- src/gfx_layout_icu.cpp | 1 + src/os/macosx/string_osx.h | 1 + src/os/windows/string_uniscribe.h | 1 + 4 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/gfx_layout_fallback.cpp b/src/gfx_layout_fallback.cpp index 1b3d020ac4..b44e874935 100644 --- a/src/gfx_layout_fallback.cpp +++ b/src/gfx_layout_fallback.cpp @@ -96,8 +96,9 @@ public: * @param c The character to add. * @return The number of buffer spaces that were used. */ -/* static */ size_t FallbackParagraphLayoutFactory::AppendToBuffer(char32_t *buff, const char32_t *buffer_last, char32_t c) +/* static */ size_t FallbackParagraphLayoutFactory::AppendToBuffer(char32_t *buff, [[maybe_unused]] const char32_t *buffer_last, char32_t c) { + assert(buff < buffer_last); *buff = c; return 1; } diff --git a/src/gfx_layout_icu.cpp b/src/gfx_layout_icu.cpp index a635c0c80c..981563c4d8 100644 --- a/src/gfx_layout_icu.cpp +++ b/src/gfx_layout_icu.cpp @@ -522,6 +522,7 @@ std::unique_ptr ICUParagraphLayout::NextLine(int /* static */ size_t ICUParagraphLayoutFactory::AppendToBuffer(UChar *buff, const UChar *buffer_last, char32_t c) { + assert(buff < buffer_last); /* Transform from UTF-32 to internal ICU format of UTF-16. */ int32_t length = 0; UErrorCode err = U_ZERO_ERROR; diff --git a/src/os/macosx/string_osx.h b/src/os/macosx/string_osx.h index 19c8ba5040..8fd9d988dc 100644 --- a/src/os/macosx/string_osx.h +++ b/src/os/macosx/string_osx.h @@ -63,6 +63,7 @@ public: */ static size_t AppendToBuffer(CharType *buff, const CharType *buffer_last, char32_t c) { + assert(buff < buffer_last); if (c >= 0x010000U) { /* Character is encoded using surrogates in UTF-16. */ if (buff + 1 <= buffer_last) { diff --git a/src/os/windows/string_uniscribe.h b/src/os/windows/string_uniscribe.h index 56537be264..0c63d468c3 100644 --- a/src/os/windows/string_uniscribe.h +++ b/src/os/windows/string_uniscribe.h @@ -45,6 +45,7 @@ public: */ static size_t AppendToBuffer(CharType *buff, const CharType *buffer_last, char32_t c) { + assert(buff < buffer_last); if (c >= 0x010000U) { /* Character is encoded using surrogates in UTF-16. */ if (buff + 1 <= buffer_last) {