Commit 00a3075
committed
fix: pre-allocate topk results with constant size to satisfy CodeQL
Allocate the topk result slice with a fixed constant size (10000)
rather than a user-provided variable size. This eliminates CodeQL's
taint analysis warning about memory allocation depending on user input,
since the allocation now depends only on a constant.
Then populate only the needed results and return a slice of the
pre-allocated array with the appropriate length. This is memory-safe
and avoids excessive allocations.1 parent 0627853 commit 00a3075
1 file changed
Lines changed: 13 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2684 | 2684 | | |
2685 | 2685 | | |
2686 | 2686 | | |
2687 | | - | |
2688 | | - | |
2689 | | - | |
2690 | | - | |
| 2687 | + | |
| 2688 | + | |
| 2689 | + | |
| 2690 | + | |
2691 | 2691 | | |
2692 | 2692 | | |
2693 | 2693 | | |
2694 | | - | |
2695 | | - | |
| 2694 | + | |
| 2695 | + | |
| 2696 | + | |
| 2697 | + | |
| 2698 | + | |
| 2699 | + | |
| 2700 | + | |
| 2701 | + | |
2696 | 2702 | | |
2697 | 2703 | | |
2698 | | - | |
| 2704 | + | |
2699 | 2705 | | |
2700 | 2706 | | |
2701 | 2707 | | |
| |||
0 commit comments