From fd9d199fd59af1d2a1f9b04b7ccfbbdbf853dc01 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Tue, 10 Feb 2026 18:51:04 +0100 Subject: [PATCH] [client,sdl] use bounds checking vector accessors --- client/SDL/SDL2/dialogs/sdl_buttons.cpp | 6 ++-- client/SDL/SDL2/dialogs/sdl_dialogs.cpp | 8 ++--- client/SDL/SDL2/dialogs/sdl_input_widgets.cpp | 12 +++---- client/SDL/SDL2/dialogs/sdl_selectlist.cpp | 6 ++-- client/SDL/SDL2/sdl_disp.cpp | 31 +++++++++---------- client/SDL/SDL3/dialogs/sdl_buttons.cpp | 6 ++-- client/SDL/SDL3/dialogs/sdl_dialogs.cpp | 8 ++--- .../dialogs/sdl_input_widget_pair_list.cpp | 13 ++++---- client/SDL/SDL3/dialogs/sdl_select_list.cpp | 6 ++-- client/SDL/SDL3/sdl_clip.cpp | 2 +- client/SDL/SDL3/sdl_context.cpp | 2 +- client/SDL/common/test/TestSDLPrefs.cpp | 18 +++++------ 12 files changed, 59 insertions(+), 59 deletions(-) diff --git a/client/SDL/SDL2/dialogs/sdl_buttons.cpp b/client/SDL/SDL2/dialogs/sdl_buttons.cpp index ff3413a27..e5b0f2a9b 100644 --- a/client/SDL/SDL2/dialogs/sdl_buttons.cpp +++ b/client/SDL/SDL2/dialogs/sdl_buttons.cpp @@ -28,7 +28,7 @@ bool SdlButtonList::populate(SDL_Renderer* renderer, const std::vector(width) + hpadding); const SDL_Rect rect = { static_cast(curOffsetX), offsetY, width, height }; - _list.emplace_back(renderer, labels[x], ids[x], rect); + _list.emplace_back(renderer, labels.at(x), ids.at(x), rect); } return true; } @@ -60,7 +60,7 @@ bool SdlButtonList::set_highlight_next(bool reset) { auto next = _highlight_index++; _highlight_index %= _list.size(); - auto& element = _list[next]; + auto& element = _list.at(next); _highlighted = &element; } return true; @@ -73,7 +73,7 @@ bool SdlButtonList::set_highlight(size_t index) _highlighted = nullptr; return false; } - auto& element = _list[index]; + auto& element = _list.at(index); _highlighted = &element; _highlight_index = ++index % _list.size(); return true; diff --git a/client/SDL/SDL2/dialogs/sdl_dialogs.cpp b/client/SDL/SDL2/dialogs/sdl_dialogs.cpp index c2fe83eed..3f3a24098 100644 --- a/client/SDL/SDL2/dialogs/sdl_dialogs.cpp +++ b/client/SDL/SDL2/dialogs/sdl_dialogs.cpp @@ -601,13 +601,13 @@ BOOL sdl_auth_dialog_show(const SDL_UserAuthArg* args) char* pwd = nullptr; if (rc > 0) { - user = _strdup(result[0].c_str()); + user = _strdup(result.at(0).c_str()); if (args->result == AUTH_SMARTCARD_PIN) - pwd = _strdup(result[1].c_str()); + pwd = _strdup(result.at(1).c_str()); else { - domain = _strdup(result[1].c_str()); - pwd = _strdup(result[2].c_str()); + domain = _strdup(result.at(1).c_str()); + pwd = _strdup(result.at(2).c_str()); } } return sdl_push_user_event(SDL_USEREVENT_AUTH_RESULT, user, domain, pwd, rc); diff --git a/client/SDL/SDL2/dialogs/sdl_input_widgets.cpp b/client/SDL/SDL2/dialogs/sdl_input_widgets.cpp index f71c47d88..7cedd6b08 100644 --- a/client/SDL/SDL2/dialogs/sdl_input_widgets.cpp +++ b/client/SDL/SDL2/dialogs/sdl_input_widgets.cpp @@ -37,7 +37,7 @@ SdlInputWidgetList::SdlInputWidgetList(const std::string& title, { SDL_SetWindowTitle(_window, title.c_str()); for (size_t x = 0; x < labels.size(); x++) - _list.emplace_back(_renderer, labels[x], initial[x], flags[x], x, widget_width, + _list.emplace_back(_renderer, labels.at(x), initial.at(x), flags.at(x), x, widget_width, widget_heigth); _buttons.populate(_renderer, buttonlabels, buttonids, total_width, @@ -79,7 +79,7 @@ bool SdlInputWidgetList::valid(ssize_t current) const auto s = static_cast(current); if (s >= _list.size()) return false; - return !_list[s].readonly(); + return !_list.at(s).readonly(); } SdlInputWidget* SdlInputWidgetList::get(ssize_t index) @@ -89,7 +89,7 @@ SdlInputWidget* SdlInputWidgetList::get(ssize_t index) auto s = static_cast(index); if (s >= _list.size()) return nullptr; - return &_list[s]; + return &_list.at(s); } SdlInputWidgetList::~SdlInputWidgetList() @@ -121,7 +121,7 @@ ssize_t SdlInputWidgetList::get_index(const SDL_MouseButtonEvent& button) assert(_list.size() <= std::numeric_limits::max()); for (size_t i = 0; i < _list.size(); i++) { - auto& cur = _list[i]; + auto& cur = _list.at(i); auto r = cur.input_rect(); if ((x >= r.x) && (x <= r.x + r.w) && (y >= r.y) && (y <= r.y + r.h)) @@ -191,7 +191,7 @@ int SdlInputWidgetList::run(std::vector& result) case SDLK_v: if (pressed.size() == 2) { - if ((pressed[0] == SDLK_LCTRL) || (pressed[0] == SDLK_RCTRL)) + if ((pressed.at(0) == SDLK_LCTRL) || (pressed.at(0) == SDLK_RCTRL)) { auto cur = get(CurrentActiveTextInput); if (cur) @@ -230,7 +230,7 @@ int SdlInputWidgetList::run(std::vector& result) } if (TextInputIndex >= 0) { - auto& cur = _list[static_cast(TextInputIndex)]; + auto& cur = _list.at(static_cast(TextInputIndex)); if (!cur.set_mouseover(_renderer, true)) throw; } diff --git a/client/SDL/SDL2/dialogs/sdl_selectlist.cpp b/client/SDL/SDL2/dialogs/sdl_selectlist.cpp index 7e17265b9..4ae7f026b 100644 --- a/client/SDL/SDL2/dialogs/sdl_selectlist.cpp +++ b/client/SDL/SDL2/dialogs/sdl_selectlist.cpp @@ -123,7 +123,7 @@ int SdlSelectList::run() reset_mouseover(); if (TextInputIndex >= 0) { - auto& cur = _list[WINPR_ASSERTING_INT_CAST(size_t, TextInputIndex)]; + auto& cur = _list.at(WINPR_ASSERTING_INT_CAST(size_t, TextInputIndex)); if (!cur.set_mouseover(_renderer, true)) throw; } @@ -159,7 +159,7 @@ int SdlSelectList::run() reset_highlight(); if (CurrentActiveTextInput >= 0) { - auto& cur = _list[WINPR_ASSERTING_INT_CAST(size_t, CurrentActiveTextInput)]; + auto& cur = _list.at(WINPR_ASSERTING_INT_CAST(size_t, CurrentActiveTextInput)); if (!cur.set_highlight(_renderer, true)) throw; } @@ -180,7 +180,7 @@ ssize_t SdlSelectList::get_index(const SDL_MouseButtonEvent& button) const Sint32 y = button.y; for (size_t i = 0; i < _list.size(); i++) { - auto& cur = _list[i]; + auto& cur = _list.at(i); auto r = cur.rect(); if ((x >= r.x) && (x <= r.x + r.w) && (y >= r.y) && (y <= r.y + r.h)) diff --git a/client/SDL/SDL2/sdl_disp.cpp b/client/SDL/SDL2/sdl_disp.cpp index c24c78aea..ee022aead 100644 --- a/client/SDL/SDL2/sdl_disp.cpp +++ b/client/SDL/SDL2/sdl_disp.cpp @@ -246,29 +246,29 @@ UINT sdlDispContext::sendLayout(const rdpMonitor* monitors, size_t nmonitors) for (size_t i = 0; i < nmonitors; i++) { auto monitor = &monitors[i]; - auto layout = &layouts[i]; + auto& layout = layouts.at(i); - layout->Flags = (monitor->is_primary ? DISPLAY_CONTROL_MONITOR_PRIMARY : 0); - layout->Left = monitor->x; - layout->Top = monitor->y; - layout->Width = WINPR_ASSERTING_INT_CAST(uint32_t, monitor->width); - layout->Height = WINPR_ASSERTING_INT_CAST(uint32_t, monitor->height); - layout->Orientation = ORIENTATION_LANDSCAPE; - layout->PhysicalWidth = monitor->attributes.physicalWidth; - layout->PhysicalHeight = monitor->attributes.physicalHeight; + layout.Flags = (monitor->is_primary ? DISPLAY_CONTROL_MONITOR_PRIMARY : 0); + layout.Left = monitor->x; + layout.Top = monitor->y; + layout.Width = WINPR_ASSERTING_INT_CAST(uint32_t, monitor->width); + layout.Height = WINPR_ASSERTING_INT_CAST(uint32_t, monitor->height); + layout.Orientation = ORIENTATION_LANDSCAPE; + layout.PhysicalWidth = monitor->attributes.physicalWidth; + layout.PhysicalHeight = monitor->attributes.physicalHeight; switch (monitor->attributes.orientation) { case 90: - layout->Orientation = ORIENTATION_PORTRAIT; + layout.Orientation = ORIENTATION_PORTRAIT; break; case 180: - layout->Orientation = ORIENTATION_LANDSCAPE_FLIPPED; + layout.Orientation = ORIENTATION_LANDSCAPE_FLIPPED; break; case 270: - layout->Orientation = ORIENTATION_PORTRAIT_FLIPPED; + layout.Orientation = ORIENTATION_PORTRAIT_FLIPPED; break; case 0: @@ -280,14 +280,13 @@ UINT sdlDispContext::sendLayout(const rdpMonitor* monitors, size_t nmonitors) * * So we default to ORIENTATION_LANDSCAPE */ - layout->Orientation = ORIENTATION_LANDSCAPE; + layout.Orientation = ORIENTATION_LANDSCAPE; break; } - layout->DesktopScaleFactor = + layout.DesktopScaleFactor = freerdp_settings_get_uint32(settings, FreeRDP_DesktopScaleFactor); - layout->DeviceScaleFactor = - freerdp_settings_get_uint32(settings, FreeRDP_DeviceScaleFactor); + layout.DeviceScaleFactor = freerdp_settings_get_uint32(settings, FreeRDP_DeviceScaleFactor); } WINPR_ASSERT(_disp); diff --git a/client/SDL/SDL3/dialogs/sdl_buttons.cpp b/client/SDL/SDL3/dialogs/sdl_buttons.cpp index d22203986..e586c5f1f 100644 --- a/client/SDL/SDL3/dialogs/sdl_buttons.cpp +++ b/client/SDL/SDL3/dialogs/sdl_buttons.cpp @@ -25,7 +25,7 @@ bool SdlButtonList::populate(std::shared_ptr& renderer, const size_t curOffsetX = offsetX + x * (static_cast(width) + hpadding); const SDL_FRect rect = { static_cast(curOffsetX), static_cast(offsetY), static_cast(width), static_cast(height) }; - auto button = std::make_shared(renderer, labels[x], ids[x], rect); + auto button = std::make_shared(renderer, labels.at(x), ids.at(x), rect); _list.emplace_back(button); } return true; @@ -58,7 +58,7 @@ bool SdlButtonList::set_highlight_next(bool reset) { auto next = _highlight_index++; _highlight_index %= _list.size(); - auto& element = _list[next]; + auto& element = _list.at(next); _highlighted = element; } return true; @@ -71,7 +71,7 @@ bool SdlButtonList::set_highlight(size_t index) _highlighted = nullptr; return false; } - auto& element = _list[index]; + auto& element = _list.at(index); _highlighted = element; _highlight_index = ++index % _list.size(); return true; diff --git a/client/SDL/SDL3/dialogs/sdl_dialogs.cpp b/client/SDL/SDL3/dialogs/sdl_dialogs.cpp index 56db550c1..e5ca4344b 100644 --- a/client/SDL/SDL3/dialogs/sdl_dialogs.cpp +++ b/client/SDL/SDL3/dialogs/sdl_dialogs.cpp @@ -613,13 +613,13 @@ BOOL sdl_auth_dialog_show(const SDL_UserAuthArg* args) char* pwd = nullptr; if (rc > 0) { - user = _strdup(result[0].c_str()); + user = _strdup(result.at(0).c_str()); if (args->result == AUTH_SMARTCARD_PIN) - pwd = _strdup(result[1].c_str()); + pwd = _strdup(result.at(1).c_str()); else { - domain = _strdup(result[1].c_str()); - pwd = _strdup(result[2].c_str()); + domain = _strdup(result.at(1).c_str()); + pwd = _strdup(result.at(2).c_str()); } } diff --git a/client/SDL/SDL3/dialogs/sdl_input_widget_pair_list.cpp b/client/SDL/SDL3/dialogs/sdl_input_widget_pair_list.cpp index dcb091a42..8597f487f 100644 --- a/client/SDL/SDL3/dialogs/sdl_input_widget_pair_list.cpp +++ b/client/SDL/SDL3/dialogs/sdl_input_widget_pair_list.cpp @@ -50,8 +50,9 @@ SdlInputWidgetPairList::SdlInputWidgetPairList(const std::string& title, { for (size_t x = 0; x < labels.size(); x++) { - auto widget = std::make_shared( - _renderer, labels[x], initial[x], flags[x], x, widget_width, widget_heigth); + auto widget = + std::make_shared(_renderer, labels.at(x), initial.at(x), + flags.at(x), x, widget_width, widget_heigth); m_list.emplace_back(widget); } @@ -95,7 +96,7 @@ bool SdlInputWidgetPairList::valid(ssize_t current) const auto s = static_cast(current); if (s >= m_list.size()) return false; - return !m_list[s]->readonly(); + return !m_list.at(s)->readonly(); } std::shared_ptr SdlInputWidgetPairList::get(ssize_t index) @@ -105,7 +106,7 @@ std::shared_ptr SdlInputWidgetPairList::get(ssize_t index) auto s = static_cast(index); if (s >= m_list.size()) return nullptr; - return m_list[s]; + return m_list.at(s); } SdlInputWidgetPairList::~SdlInputWidgetPairList() @@ -133,7 +134,7 @@ ssize_t SdlInputWidgetPairList::get_index(const SDL_MouseButtonEvent& button) const auto y = button.y; for (size_t i = 0; i < m_list.size(); i++) { - auto& cur = m_list[i]; + auto& cur = m_list.at(i); auto r = cur->input_rect(); if ((x >= r.x) && (x <= r.x + r.w) && (y >= r.y) && (y <= r.y + r.h)) @@ -240,7 +241,7 @@ int SdlInputWidgetPairList::run(std::vector& result) } if (TextInputIndex >= 0) { - auto& cur = m_list[static_cast(TextInputIndex)]; + auto& cur = m_list.at(static_cast(TextInputIndex)); cur->set_mouseover(true); } diff --git a/client/SDL/SDL3/dialogs/sdl_select_list.cpp b/client/SDL/SDL3/dialogs/sdl_select_list.cpp index f52a10dcc..d58bf8005 100644 --- a/client/SDL/SDL3/dialogs/sdl_select_list.cpp +++ b/client/SDL/SDL3/dialogs/sdl_select_list.cpp @@ -106,7 +106,7 @@ int SdlSelectList::run() reset_mouseover(); if (TextInputIndex >= 0) { - auto& cur = _list[WINPR_ASSERTING_INT_CAST(size_t, TextInputIndex)]; + auto& cur = _list.at(WINPR_ASSERTING_INT_CAST(size_t, TextInputIndex)); if (!cur.mouseover(true)) throw; } @@ -142,7 +142,7 @@ int SdlSelectList::run() reset_highlight(); if (CurrentActiveTextInput >= 0) { - auto& cur = _list[WINPR_ASSERTING_INT_CAST(size_t, CurrentActiveTextInput)]; + auto& cur = _list.at(WINPR_ASSERTING_INT_CAST(size_t, CurrentActiveTextInput)); if (!cur.highlight(true)) throw; } @@ -174,7 +174,7 @@ ssize_t SdlSelectList::get_index(const SDL_MouseButtonEvent& button) const auto y = button.y; for (size_t i = 0; i < _list.size(); i++) { - auto& cur = _list[i]; + auto& cur = _list.at(i); auto r = cur.rect(); if ((x >= r.x) && (x <= r.x + r.w) && (y >= r.y) && (y <= r.y + r.h)) diff --git a/client/SDL/SDL3/sdl_clip.cpp b/client/SDL/SDL3/sdl_clip.cpp index 6b12faa19..248ca0f22 100644 --- a/client/SDL/SDL3/sdl_clip.cpp +++ b/client/SDL/SDL3/sdl_clip.cpp @@ -609,7 +609,7 @@ std::shared_ptr sdlClip::ReceiveFormatDataRequestHandle( case CF_DIB: case CF_DIBV5: - mime = s_mime_bitmap()[0]; + mime = s_mime_bitmap().at(0); localFormatId = ClipboardGetFormatId(clipboard->_system, mime); break; diff --git a/client/SDL/SDL3/sdl_context.cpp b/client/SDL/SDL3/sdl_context.cpp index a1714b3b4..2b78c531e 100644 --- a/client/SDL/SDL3/sdl_context.cpp +++ b/client/SDL/SDL3/sdl_context.cpp @@ -1359,7 +1359,7 @@ int64_t SdlContext::monitorId(uint32_t index) const { return -1; } - return _monitorIds[index]; + return _monitorIds.at(index); } void SdlContext::push(std::vector&& rects) diff --git a/client/SDL/common/test/TestSDLPrefs.cpp b/client/SDL/common/test/TestSDLPrefs.cpp index db4a75302..b89b8c698 100644 --- a/client/SDL/common/test/TestSDLPrefs.cpp +++ b/client/SDL/common/test/TestSDLPrefs.cpp @@ -90,18 +90,18 @@ int TestSDLPrefs(int argc, char* argv[]) if (array_value.size() != 3) return -1; #if defined(WITH_WINPR_JSON) - if (array_value[0] != "a") + if (array_value.at(0) != "a") return -1; - if (array_value[1] != "b") + if (array_value.at(1) != "b") return -1; - if (array_value[2] != "c") + if (array_value.at(2) != "c") return -1; #else - if (array_value[0] != "c") + if (array_value.at(0) != "c") return -1; - if (array_value[1] != "b") + if (array_value.at(1) != "b") return -1; - if (array_value[2] != "a") + if (array_value.at(2) != "a") return -1; #endif @@ -110,11 +110,11 @@ int TestSDLPrefs(int argc, char* argv[]) if (array_value_nonexistent.size() != 3) return -1; - if (array_value_nonexistent[0] != "c") + if (array_value_nonexistent.at(0) != "c") return -1; - if (array_value_nonexistent[1] != "b") + if (array_value_nonexistent.at(1) != "b") return -1; - if (array_value_nonexistent[2] != "a") + if (array_value_nonexistent.at(2) != "a") return -1; return 0;