From 5e8e4b90c1fef032db8432546fdfcc008deba4b4 Mon Sep 17 00:00:00 2001 From: Xavier Arteaga Date: Fri, 7 Jan 2022 10:30:54 +0100 Subject: [PATCH] Fix memory access in SSB search and measure --- lib/src/phy/sync/ssb.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/src/phy/sync/ssb.c b/lib/src/phy/sync/ssb.c index 495d5fdb9..738d25613 100644 --- a/lib/src/phy/sync/ssb.c +++ b/lib/src/phy/sync/ssb.c @@ -884,8 +884,21 @@ static int ssb_pss_search(srsran_ssb_t* q, // Reset best correlation best_corr = 0.0f; + // Number of samples taken in this iteration + uint32_t n = q->corr_sz; + + // Detect if the correlation input exceeds the input length, take the maximum amount of samples + if (best_delay + q->corr_sz > nof_samples) { + n = nof_samples - best_delay; + } + // Copy the amount of samples - srsran_vec_cf_copy(q->tmp_time, &in[best_delay], q->corr_sz); + srsran_vec_cf_copy(q->tmp_time, &in[best_delay], n); + + // Append zeros if there is space left + if (n < q->corr_sz) { + srsran_vec_cf_zero(&q->tmp_time[n], q->corr_sz - n); + } // Convert to frequency domain srsran_dft_run_guru_c(&q->fft_corr);