From beb4c64f23aa0d9133914a7a198d427e3719b0ac Mon Sep 17 00:00:00 2001 From: Gabriel Fedel Date: Fri, 26 Jul 2024 18:03:25 +0200 Subject: [PATCH] fix: Correct access out of bonds on buffer used by flash functions This commit fixes access out of bonds from flash.cpp. With this fix it is possible to use the flash functions (write and info) with source compile with gcc >= 11 --- mrfCommon/src/flash.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/mrfCommon/src/flash.cpp b/mrfCommon/src/flash.cpp index 04ed73b7..ec0fed50 100644 --- a/mrfCommon/src/flash.cpp +++ b/mrfCommon/src/flash.cpp @@ -371,14 +371,16 @@ void CFIFlash::busyWait(double timeout, unsigned n) CFIStreamBuf::CFIStreamBuf(CFIFlash& flash) :flash(flash) ,pos(0u) -{} +{ + buf.resize(1); +} CFIStreamBuf::int_type CFIStreamBuf::underflow() { // read-ahead is only one page - buf.resize(flash.pageSize()); + buf.resize(std::max(1u, flash.pageSize())); flash.read(pos, buf.size(), (epicsUInt8*)&buf[0]); - setg(&buf[0], &buf[0], &buf[buf.size()]); + setg(&buf[0], &buf[0], &buf[buf.size()-1u]); pos += buf.size(); return buf[0];