aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcopilot-swe-agent[bot]2026-02-20 06:46:27 +0000
committercopilot-swe-agent[bot]2026-02-20 06:46:27 +0000
commit691a7b1090582e52564da3e660239bd4258ef803 (patch)
treeedb810a8c0c37ae4469d6f0d606641f5eece2ef1
parent11b4ff772bdd09ba9d80c35615ca63b97a494a1a (diff)
downloadlibrandom-691a7b1090582e52564da3e660239bd4258ef803.tar.xz
librandom-691a7b1090582e52564da3e660239bd4258ef803.tar.zst
Add safety check and clarifying comment for array bounds
Co-authored-by: 8e8m <248551607+8e8m@users.noreply.github.com>
-rw-r--r--source/photon_spin_random.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/source/photon_spin_random.c b/source/photon_spin_random.c
index 5d76806..abb2b03 100644
--- a/source/photon_spin_random.c
+++ b/source/photon_spin_random.c
@@ -55,8 +55,11 @@ static void generate_block(photon_spin_random_t *rng) {
k++;
}
- /* Check for collision patterns and perturb if needed */
- if (rng->elements[k - 1] == rng->elements[k - 2] &&
+ /* Check for collision patterns and perturb if needed.
+ * Note: k is always 5, 10, 15, or 20 here (after the inner loop),
+ * so k-5 is always >= 0 (safe array access) */
+ if (k >= 5 &&
+ rng->elements[k - 1] == rng->elements[k - 2] &&
rng->elements[k - 3] == rng->elements[k - 4]) {
rng->elements[k - 1] += mix[i] ^ 81016U;
rng->elements[k - 2] += mix[i] ^ 297442265U;