From c30b4e4b384bd746a37e503d140ac9e61ebe468b Mon Sep 17 00:00:00 2001 From: Sergey Mikhno Date: Sun, 26 Jul 2026 21:52:39 +0300 Subject: [PATCH] Fix out-of-bounds std::vector access causing R session abort Use data() + offset instead of &snip operator[] to avoid triggering _GLIBCXX_ASSERTIONS when computing past-the-end pointers. The old code called operator[] with index == size(), which is undefined behavior and causes a crash on Arch Linux, Fedora, and other distros with _GLIBCXX_ASSERTIONS enabled. --- src/word2vec/lib/word2vec.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/word2vec/lib/word2vec.cpp b/src/word2vec/lib/word2vec.cpp index ea717a3..56d6533 100644 --- a/src/word2vec/lib/word2vec.cpp +++ b/src/word2vec/lib/word2vec.cpp @@ -69,9 +69,9 @@ namespace w2v { for (auto const &i:words) { auto &v = m_map[i]; v.resize(m_vectorSize); - std::copy(&_trainMatrix[wordIndex * m_vectorSize], - &_trainMatrix[(wordIndex + 1) * m_vectorSize], - &v[0]); + std::copy(_trainMatrix.data() + wordIndex * m_vectorSize, + _trainMatrix.data() + (wordIndex + 1) * m_vectorSize, + v.data()); wordIndex++; }