# std.sort.pdq: fix out-of-bounds access in partialInsertionSort \(\#25253\) · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/6dd0270a1926661e339d993a825fffa82be6bd51)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: 6dd0270a1926661e339d993a825fffa82be6bd51

Requested commit: 6dd0270a1926661e339d993a825fffa82be6bd51

Commit: 6dd0270a1926661e339d993a825fffa82be6bd51

Tree: 6f7e7cfa8f35001fea399408cfa39b91c96ee1c9

Author: Frank Denis

Committer: GitHub

## Message

```
std.sort.pdq: fix out-of-bounds access in partialInsertionSort (#25253)

* std.sort.pdq: fix out-of-bounds access in partialInsertionSort

When sorting a sub-range that doesn't start at index 0, the
partialInsertionSort function could access indices below the range
start. The loop condition `while (j >= 1)` didn't respect the
arbitrary range boundaries [a, b).

This changes the condition to `while (j > a)` to ensure indices
never go below the range start, fixing the issue where pdqContext
would access out-of-bounds indices.

Fixes #25250

```

## Parents

- [4314c9653a874451d1c9b3dbb8be08d966344028](https://git.cafe/gitcafe/zig/commit/4314c9653a874451d1c9b3dbb8be08d966344028?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/6dd0270a1926661e339d993a825fffa82be6bd51?format=markdown)
