From 45d2bef4bbf8a6432f47dd35f6667f3e93244a25 Mon Sep 17 00:00:00 2001 From: Kaiqi Yan Date: Thu, 12 Mar 2026 04:17:54 +0000 Subject: [PATCH] Fix OOB r/w issues Signed-off-by: Kaiqi Yan --- libs/qec/lib/decoders/sliding_window.cpp | 4 ++++ libs/solvers/lib/adapt/device/adapt.cpp | 5 ++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/libs/qec/lib/decoders/sliding_window.cpp b/libs/qec/lib/decoders/sliding_window.cpp index d936b923..8da3cd4a 100644 --- a/libs/qec/lib/decoders/sliding_window.cpp +++ b/libs/qec/lib/decoders/sliding_window.cpp @@ -293,6 +293,10 @@ decoder_result sliding_window::decode(const std::vector &syndrome) { std::vector sliding_window::decode_batch( const std::vector> &syndromes) { + if (syndromes.empty()) { + CUDAQ_DBG("Returning empty decoder_result (no syndrome)"); + return {}; + } if (syndromes[0].size() == this->syndrome_size) { CUDAQ_DBG("Decoding whole block"); // Decode the whole thing, iterating over windows manually. diff --git a/libs/solvers/lib/adapt/device/adapt.cpp b/libs/solvers/lib/adapt/device/adapt.cpp index 28946dc3..28cebbd3 100644 --- a/libs/solvers/lib/adapt/device/adapt.cpp +++ b/libs/solvers/lib/adapt/device/adapt.cpp @@ -22,12 +22,11 @@ adapt_kernel(std::size_t numQubits, statePrep(q); auto i = 0; - for (std::size_t j = 0; j < trotterOpList.size();) { + for (std::size_t j = 0; j < trotterOpList.size(); ++j) { auto index = poolIndices[j]; auto &term = trotterOpList[j]; exp_pauli(thetas[i] * coefficients[j], q, term); - j++; - if (index != poolIndices[j]) { + if (j + 1 < poolIndices.size() && index != poolIndices[j + 1]) { i++; } }