diff options
-rw-r--r-- | src/Editor.cxx | 4 | ||||
-rw-r--r-- | src/Platform.h | 2 | ||||
-rw-r--r-- | src/PositionCache.cxx | 7 | ||||
-rw-r--r-- | src/RESearch.cxx | 31 | ||||
-rw-r--r-- | win32/ScintillaWin.cxx | 12 |
5 files changed, 33 insertions, 23 deletions
diff --git a/src/Editor.cxx b/src/Editor.cxx index c2c31f0d1..08ee3fc6a 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -1937,9 +1937,7 @@ SelectionPosition Editor::RealizeVirtualSpace(const SelectionPosition &position) } void Editor::AddChar(char ch) { - char s[2]; - s[0] = ch; - s[1] = '\0'; + const char s[1] {ch}; InsertCharacter(std::string_view(s, 1), CharacterSource::DirectInput); } diff --git a/src/Platform.h b/src/Platform.h index ce04d9b22..b0d12888d 100644 --- a/src/Platform.h +++ b/src/Platform.h @@ -319,7 +319,7 @@ struct ListOptions { class ListBox : public Window { public: ListBox() noexcept; - virtual ~ListBox() noexcept override; + ~ListBox() noexcept override; static std::unique_ptr<ListBox> Allocate(); virtual void SetFont(const Font *font)=0; diff --git a/src/PositionCache.cxx b/src/PositionCache.cxx index 23733c3a0..fc27dce77 100644 --- a/src/PositionCache.cxx +++ b/src/PositionCache.cxx @@ -87,11 +87,12 @@ LineLayout::~LineLayout() { void LineLayout::Resize(int maxLineLength_) { if (maxLineLength_ > maxLineLength) { Free(); - chars = std::make_unique<char[]>(maxLineLength_ + 1); - styles = std::make_unique<unsigned char []>(maxLineLength_ + 1); + const size_t lineAllocation = maxLineLength_ + 1; + chars = std::make_unique<char[]>(lineAllocation); + styles = std::make_unique<unsigned char []>(lineAllocation); // Extra position allocated as sometimes the Windows // GetTextExtentExPoint API writes an extra element. - positions = std::make_unique<XYPOSITION []>(maxLineLength_ + 1 + 1); + positions = std::make_unique<XYPOSITION []>(lineAllocation + 1); if (bidiData) { bidiData->Resize(maxLineLength_); } diff --git a/src/RESearch.cxx b/src/RESearch.cxx index 15f3d6281..9a2981ffe 100644 --- a/src/RESearch.cxx +++ b/src/RESearch.cxx @@ -305,6 +305,7 @@ constexpr unsigned char escapeValue(unsigned char ch) noexcept { case 'r': return '\r'; case 't': return '\t'; case 'v': return '\v'; + default: break; } return 0; } @@ -353,7 +354,7 @@ int RESearch::GetBackslashExpression( // I choose to interpret unexpected syntax in a logical way instead // of reporting errors. Otherwise, we can stick on, eg., PCRE behaviour. incr = 0; // Most of the time, will skip the char "naturally". - int c; + int c = 0; int result = -1; const unsigned char bsc = *pattern; if (!bsc) { @@ -433,16 +434,18 @@ int RESearch::GetBackslashExpression( const char *RESearch::Compile(const char *pattern, Sci::Position length, bool caseSensitive, bool posix) noexcept { char *mp=nfa; /* nfa pointer */ - char *lp; /* saved pointer */ + char *lp=nullptr; /* saved pointer */ char *sp=nfa; /* another one */ - char *mpMax = mp + MAXNFA - BITBLK - 10; + const char * mpMax = mp + MAXNFA - BITBLK - 10; int tagi = 0; /* tag stack index */ int tagc = 1; /* actual tag count */ - int n; - char mask; /* xor mask -CCL/NCL */ - int c1, c2, prevChar; + int n = 0; + char mask = 0; /* xor mask -CCL/NCL */ + int c1 = 0; + int c2 = 0; + int prevChar = 0; if (!pattern || !length) { if (sta) @@ -753,7 +756,7 @@ const char *RESearch::Compile(const char *pattern, Sci::Position length, bool ca * */ int RESearch::Execute(const CharacterIndexer &ci, Sci::Position lp, Sci::Position endp) { - unsigned char c; + unsigned char c = 0; Sci::Position ep = NOTFOUND; char *ap = nfa; @@ -841,12 +844,14 @@ int RESearch::Execute(const CharacterIndexer &ci, Sci::Position lp, Sci::Positio #define CCLSKIP 34 /* [CLO] CCL 32 bytes END */ Sci::Position RESearch::PMatch(const CharacterIndexer &ci, Sci::Position lp, Sci::Position endp, char *ap) { - int op, c, n; - Sci::Position e; /* extra pointer for CLO */ - Sci::Position bp; /* beginning of subpat... */ - Sci::Position ep; /* ending of subpat... */ - Sci::Position are; /* to save the line ptr. */ - Sci::Position llp; /* lazy lp for LCLO */ + int op = 0; + int c = 0; + int n = 0; + Sci::Position e = 0; /* extra pointer for CLO */ + Sci::Position bp = 0; /* beginning of subpat... */ + Sci::Position ep = 0; /* ending of subpat... */ + Sci::Position are = 0; /* to save the line ptr. */ + Sci::Position llp = 0; /* lazy lp for LCLO */ while ((op = *ap++) != END) switch (op) { diff --git a/win32/ScintillaWin.cxx b/win32/ScintillaWin.cxx index ce9eca9f6..92d86080f 100644 --- a/win32/ScintillaWin.cxx +++ b/win32/ScintillaWin.cxx @@ -141,9 +141,11 @@ bool KeyboardIsKeyDown(int key) noexcept { return (::GetKeyState(key) & 0x80000000) != 0; } +// Bit 24 is the extended keyboard flag and the numeric keypad is non-extended +constexpr sptr_t extendedKeyboard = 1 << 24; + constexpr bool KeyboardIsNumericKeypadFunction(uptr_t wParam, sptr_t lParam) { - // Bit 24 is the extended keyboard flag and the numeric keypad is non-extended - if ((lParam & (1 << 24)) != 0) { + if ((lParam & extendedKeyboard) != 0) { // Not from the numeric keypad return false; } @@ -586,7 +588,11 @@ void ScintillaWin::Finalise() { bool ScintillaWin::UpdateRenderingParams(bool force) noexcept { if (!renderingParams) { - renderingParams = std::make_shared<RenderingParams>(); + try { + renderingParams = std::make_shared<RenderingParams>(); + } catch (const std::bad_alloc &) { + return false; + } } HMONITOR monitor = ::MonitorFromWindow(MainHWND(), MONITOR_DEFAULTTONEAREST); if (!force && monitor == hCurrentMonitor && renderingParams->defaultRenderingParams) { |