From 22c7c33a637008d12c060a1f1b6fa271e605b888 Mon Sep 17 00:00:00 2001 From: jerrrrycho Date: Sat, 10 Oct 2026 16:22:49 +0200 Subject: [PATCH] refactor(sonar): use std::size for array lengths (cpp:S7127) Co-Authored-By: Claude Opus 5.5 --- McZapkie/Mover.cpp | 16 ++++++++-------- gl/buffer.cpp | 2 +- utilities/uart.cpp | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/McZapkie/Mover.cpp b/McZapkie/Mover.cpp index 0241380d..91073f50 100644 --- a/McZapkie/Mover.cpp +++ b/McZapkie/Mover.cpp @@ -6892,7 +6892,7 @@ bool TMoverParameters::AutoRelayCheck(void) // return ARC;// bbylo exit; //Ra: to powoduje, że EN57 nie wyłącza się przy IminLo } // main bez samoczynnego rozruchu - if (MainCtrlActualPos < sizeof(RList) / sizeof(TScheme) - 1 // crude guard against running out of current fixed table + if (MainCtrlActualPos < std::size(RList) - 1 // crude guard against running out of current fixed table && (RList[MainCtrlActualPos].Relay < MainCtrlPos || (RList[MainCtrlActualPos + 1].Relay == MainCtrlPos && MainCtrlActualPos < RlistSize) || (TrainType == dt_ET22 && DelayCtrlFlag))) { @@ -9231,7 +9231,7 @@ bool TMoverParameters::readRList(std::string const &Input) return false; } auto idx = LISTLINE++; - if (idx >= sizeof(RList) / sizeof(TScheme)) + if (idx >= std::size(RList)) { WriteLog("Read RList: number of entries exceeded capacity of the data table"); return false; @@ -9256,7 +9256,7 @@ bool TMoverParameters::readUCList(std::string const &line) cParser parser(line); parser.getTokens(10, false); auto idx = LISTLINE++; - if (idx >= sizeof(UniCtrlList) / sizeof(TUniversalCtrl)) + if (idx >= std::size(UniCtrlList)) { WriteLog("Read UCList: number of entries exceeded capacity of the data table"); return false; @@ -9274,7 +9274,7 @@ bool TMoverParameters::readDList(std::string const &line) cParser parser(line); parser.getTokens(3, false); auto idx = LISTLINE++; - if (idx >= sizeof(RList) / sizeof(TScheme)) + if (idx >= std::size(RList)) { WriteLog("Read DList: number of entries exceeded capacity of the data table"); return false; @@ -9374,7 +9374,7 @@ bool TMoverParameters::readFFList(std::string const &line) return false; } int idx = LISTLINE++; - if (idx >= sizeof(FFlist) / sizeof(TFFScheme)) + if (idx >= std::size(FFlist)) { WriteLog("Read FList: number of entries exceeded capacity of the data table"); return false; @@ -9394,7 +9394,7 @@ bool TMoverParameters::readFFEDList(std::string const &line) return false; } int idx = LISTLINE++; - if (idx >= sizeof(FFEDlist) / sizeof(TFFScheme)) + if (idx >= std::size(FFEDlist)) { WriteLog("Read FList: number of entries exceeded capacity of the data table"); return false; @@ -9414,7 +9414,7 @@ bool TMoverParameters::readWiperList(std::string const &line) return false; } int idx = LISTLINE++; - if (idx >= sizeof(WiperList) / sizeof(TWiperScheme)) + if (idx >= std::size(WiperList)) { WriteLog("Read WiperList: number of entries exceeded capacity of the data table"); return false; @@ -9450,7 +9450,7 @@ bool TMoverParameters::readWWList(std::string const &line) return false; } int idx = LISTLINE++; - if (idx >= sizeof(DElist) / sizeof(TDEScheme)) + if (idx >= std::size(DElist)) { WriteLog("Read WWList: number of entries exceeded capacity of the data table"); return false; diff --git a/gl/buffer.cpp b/gl/buffer.cpp index 04ec479c..6a0ab032 100644 --- a/gl/buffer.cpp +++ b/gl/buffer.cpp @@ -47,7 +47,7 @@ void gl::buffer::unbind(targets target) void gl::buffer::unbind() { - for (size_t i = 0; i < sizeof(binding_points) / sizeof(GLuint); i++) + for (size_t i = 0; i < std::size(binding_points); i++) unbind((targets)i); } diff --git a/utilities/uart.cpp b/utilities/uart.cpp index 69963bc4..aa441491 100644 --- a/utilities/uart.cpp +++ b/utilities/uart.cpp @@ -28,7 +28,7 @@ const char* uart_baudrates_list[] = { "2000000" }; -const size_t uart_baudrates_list_num = sizeof(uart_baudrates_list) / sizeof(uart_baudrates_list[0]); +const size_t uart_baudrates_list_num = std::size(uart_baudrates_list); void uart_status::reset_stats() { packets_sent = 0;