Quellcode durchsuchen

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.
Brian Gianforcaro vor 3 Jahren
Ursprung
Commit
ea2d68d14b
1 geänderte Dateien mit 2 neuen und 2 gelöschten Zeilen
  1. 2 2
      Userland/Applications/Assistant/FuzzyMatch.cpp

+ 2 - 2
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);
 }