From ea2d68d14bc48ddadd2ba145b16a01cdf86bf000 Mon Sep 17 00:00:00 2001 From: Brian Gianforcaro Date: Mon, 27 Sep 2021 19:39:46 -0700 Subject: [PATCH] Assistant: Zero initialize fuzzy match array SonarCloud flagged the read of the matches array as a potential garbage read. I don't believe the case it flagged was possible to reach due to how the code is structured, however we should really just be zero initializing these stack arrays. --- Userland/Applications/Assistant/FuzzyMatch.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Userland/Applications/Assistant/FuzzyMatch.cpp b/Userland/Applications/Assistant/FuzzyMatch.cpp index 8043e34c21..e021637a83 100644 --- a/Userland/Applications/Assistant/FuzzyMatch.cpp +++ b/Userland/Applications/Assistant/FuzzyMatch.cpp @@ -51,7 +51,7 @@ static FuzzyMatchResult fuzzy_match_recursive(String const& needle, String const first_match = false; } - u8 recursive_matches[recursive_match_limit]; + u8 recursive_matches[recursive_match_limit] {}; auto result = fuzzy_match_recursive(needle, haystack, needle_idx, haystack_idx + 1, matches, recursive_matches, next_match, recursion_count); if (result.matched) { if (!had_recursive_match || result.score > best_recursive_score) { @@ -116,7 +116,7 @@ static FuzzyMatchResult fuzzy_match_recursive(String const& needle, String const FuzzyMatchResult fuzzy_match(String needle, String haystack) { int recursion_count = 0; - u8 matches[MAX_MATCHES]; + u8 matches[MAX_MATCHES] {}; return fuzzy_match_recursive(needle, haystack, 0, 0, nullptr, matches, 0, recursion_count); }