From 72d7aa9575c76c5763877e6f6e9a3b5f5a0a786d Mon Sep 17 00:00:00 2001 From: Debug_pro <63473508+Debug-pro-dev@users.noreply.github.com> Date: Thu, 12 Feb 2026 01:22:45 +0300 Subject: [PATCH] some sec fixes --- FibonacciWindow.xaml.cs | 2 +- Matrices.cs | 4 +++- MatrixFlipWindow.xaml.cs | 6 ++++++ Parsers.cs | 5 +++-- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/FibonacciWindow.xaml.cs b/FibonacciWindow.xaml.cs index a33fbc9..c51be05 100644 --- a/FibonacciWindow.xaml.cs +++ b/FibonacciWindow.xaml.cs @@ -35,7 +35,7 @@ namespace Lab long a = 1; long b = 1; List list = new List(); - while (a < n) { list.Add(a); long next = a + b; a = b; b = next; } + while (a < n) { list.Add(a); if (long.MaxValue - a < b) break; long next = a + b; a = b; b = next; } OutBox.Text = string.Join(", ", list); InfoText.Text = $"Найдено чисел: {list.Count}."; diff --git a/Matrices.cs b/Matrices.cs index 56566cc..4c767f1 100644 --- a/Matrices.cs +++ b/Matrices.cs @@ -79,7 +79,9 @@ namespace Lab { for (int col = 0; col < cols; col++) { - array[row, col] = Convert.ToInt32(dt.Rows[row][col]); + double num = (double)dt.Rows[row][col]; + num = double.IsInfinity(num) || double.IsNaN(num) ? 0 : num; + array[row, col] = Convert.ToInt32(num); } } diff --git a/MatrixFlipWindow.xaml.cs b/MatrixFlipWindow.xaml.cs index f4e7255..c29c856 100644 --- a/MatrixFlipWindow.xaml.cs +++ b/MatrixFlipWindow.xaml.cs @@ -41,6 +41,12 @@ namespace Lab return false; } + if (rows > 50 || cols > 50) + { + FlipInfoText.Text = "Возможно, но превосходит вычислительные мощности."; + return false; + } + return true; } diff --git a/Parsers.cs b/Parsers.cs index 19b817f..7bc4ef7 100644 --- a/Parsers.cs +++ b/Parsers.cs @@ -3,12 +3,13 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Globalization; namespace Lab { internal class Parsers { - public static bool TryParseDouble(string? s, out double val) => double.TryParse((s ?? "").Trim().Replace(",", "."), out val); + public static bool TryParseDouble(string? s, out double val) => double.TryParse((s ?? "").Trim().Replace(",", "."), NumberStyles.Float, CultureInfo.InvariantCulture, out val) && !double.IsNaN(val) && !double.IsInfinity(val); public static bool TryParseInt(string? s, out int val) => int.TryParse((s ?? "").Trim(), out val); public static bool TryParseDoubleArray(string? s, out double[] vals, out string err) @@ -21,7 +22,7 @@ namespace Lab return false; } - string[] parts = s.Split(new[] { ' ', '\t', '\n', '\r', ',', ';' }); + string[] parts = s.Split(new[] { ' ', '\t', '\n', '\r', ',', ';' }, StringSplitOptions.RemoveEmptyEntries); List list = new List();