Skip to content

Commit 2d8ed5a

Browse files
authored
Fix out-of-bounds access in IT66021_Get_VTMG() bubble sort
The inner loop in IT66021_Get_VTMG() reads r9a[j+1] while iterating j from IT66121_9A_READ_N - 1, which can access one element past the end of the array. This change adjusts the loop bound to prevent out-of-bounds access while preserving the existing sorting behavior. Is a full refactor necessary to address the bounds violation?
1 parent f1b6c45 commit 2d8ed5a

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

src/driver/it66021.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ int IT66021_Get_VTMG(int *freq_ref) {
232232
}
233233

234234
for (i = 0; i < IT66121_9A_READ_N; i++) {
235-
for (j = IT66121_9A_READ_N - 1; j >= i; j--) {
235+
for (j = IT66121_9A_READ_N - 2; j >= i; j--) {
236236
if (r9a[j] > r9a[j + 1]) {
237237
int temp = r9a[j];
238238
r9a[j] = r9a[j + 1];

0 commit comments

Comments
 (0)