Skip to content

Commit

Permalink
fix: Correct access out of bonds on buffer used by flash functions
Browse files Browse the repository at this point in the history
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
  • Loading branch information
gabrielfedel committed Aug 6, 2024
1 parent 5b0c1a1 commit beb4c64
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions mrfCommon/src/flash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down

0 comments on commit beb4c64

Please sign in to comment.