Skip to content

Commit 9e97007

Browse files
franklinicclaude
andcommitted
fix: replace unsafe cast with interface method in CombineWith
Replace direct cast to PruningMask<T> with GetMaskData() interface method in the CombineWith method. This addresses the code scanning issue about defensive casting and uses proper interface-based programming instead of implementation-specific casting. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 7241507 commit 9e97007

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

src/Pruning/PruningMask.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,16 +359,20 @@ public IPruningMask<T> CombineWith(IPruningMask<T> otherMask)
359359
throw new ArgumentException("Masks must have same shape to combine");
360360

361361
var combined = new Matrix<T>(_mask.Rows, _mask.Columns);
362-
var otherMatrix = ((PruningMask<T>)otherMask)._mask;
363362

363+
// Use interface method to get mask data instead of unsafe casting
364+
var otherData = otherMask.GetMaskData();
365+
366+
int idx = 0;
364367
for (int i = 0; i < _mask.Rows; i++)
365368
{
366369
for (int j = 0; j < _mask.Columns; j++)
367370
{
368-
// Logical AND: both must be 1 to keep
371+
// Logical AND: both must be non-zero to keep
369372
bool keep = !_numOps.Equals(_mask[i, j], _numOps.Zero) &&
370-
!_numOps.Equals(otherMatrix[i, j], _numOps.Zero);
373+
!_numOps.Equals(otherData[idx], _numOps.Zero);
371374
combined[i, j] = keep ? _numOps.One : _numOps.Zero;
375+
idx++;
372376
}
373377
}
374378

0 commit comments

Comments
 (0)