Skip to content

Fix for Missed opportunity to use Where#26

Merged
guitarrapc merged 1 commit intomainfrom
finding-autofix-90417414
Mar 3, 2026
Merged

Fix for Missed opportunity to use Where#26
guitarrapc merged 1 commit intomainfrom
finding-autofix-90417414

Conversation

@guitarrapc
Copy link
Collaborator

In general terms, the fix is to make the filtering of columnDefinitions explicit by using LINQ’s Where method before iterating, instead of iterating all elements and skipping some with continue. This both addresses the CodeQL warning and makes the intent clearer: only columns whose names are present in indexKeyNames are processed.

The best way to fix this without changing existing functionality is:

  • Replace the foreach (var column in columnDefinitions) loop plus the if (!indexKeyNames.Contains(column.Name)) continue; guard with a foreach over a filtered sequence, such as foreach (var column in columnDefinitions.Where(column => indexKeyNames.Contains(column.Name))).
  • Keep the contents of the loop body (the mapper(column) call and the inner foreach over this.Indexes.Where(...)) unchanged.

To implement this:

  • Modify AddKeyReferenceOnColumnCore in src/MySQLToCsharp.Parser/MySqlDefinitions.cs, around lines 364–379.
  • Because the snippet already uses LINQ methods (Select, Where) on this.Indexes, the necessary using System.Linq; is presumably already present elsewhere in the file or project; if it is not, add it at the top of this file. We will not change any other behavior or structure.

Suggested fixes powered by Copilot Autofix. Review carefully before merging.

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@guitarrapc guitarrapc marked this pull request as ready for review March 3, 2026 09:44
@guitarrapc guitarrapc enabled auto-merge March 3, 2026 09:46
@guitarrapc guitarrapc merged commit d790fac into main Mar 3, 2026
5 checks passed
@guitarrapc guitarrapc deleted the finding-autofix-90417414 branch March 3, 2026 09:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant