From 440e8f9c228b9284efdea60136aadc3893aa9bce Mon Sep 17 00:00:00 2001 From: orbitcowboy Date: Tue, 10 May 2022 09:30:13 +0200 Subject: [PATCH] std.cfg: Improved configuration of std::ofstream::write(), std::ostringstream::write(), std::ostream::write() and std::fstream(). --- cfg/std.cfg | 4 ++++ test/cfg/std.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/cfg/std.cfg b/cfg/std.cfg index 78ff19f63..44ca631d8 100644 --- a/cfg/std.cfg +++ b/cfg/std.cfg @@ -6411,6 +6411,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun + @@ -6425,6 +6426,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun + @@ -6439,6 +6441,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun + @@ -6453,6 +6456,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun + diff --git a/test/cfg/std.cpp b/test/cfg/std.cpp index 57a3fc15c..a73e98358 100644 --- a/test/cfg/std.cpp +++ b/test/cfg/std.cpp @@ -27,12 +27,53 @@ #include #include #include +#include #include #include #include #include +void bufferAccessOutOfBounds_std_fstream_write(std::fstream &fs, const char* s, std::streamsize n) +{ + char buf[42] = {0}; + (void)fs.write(buf,42); + // cppcheck-suppress bufferAccessOutOfBounds + (void)fs.write(buf,43); + (void)fs.write(buf,n); + (void)fs.write(s,n); +} + +void bufferAccessOutOfBounds_std_ostream_write(std::ostream &os, const char* s, std::streamsize n) +{ + char buf[42] = {0}; + (void)os.write(buf,42); + // cppcheck-suppress bufferAccessOutOfBounds + (void)os.write(buf,43); + (void)os.write(buf,n); + (void)os.write(s,n); +} + +void bufferAccessOutOfBounds_std_ostringstream_write(std::ostringstream &oss, const char* s, std::streamsize n) +{ + char buf[42] = {0}; + (void)oss.write(buf,42); + // cppcheck-suppress bufferAccessOutOfBounds + (void)oss.write(buf,43); + (void)oss.write(buf,n); + (void)oss.write(s,n); +} + +void bufferAccessOutOfBounds_std_ofstream_write(std::ofstream &os, const char* s, std::streamsize n) +{ + char buf[42] = {0}; + (void)os.write(buf,42); + // cppcheck-suppress bufferAccessOutOfBounds + (void)os.write(buf,43); + (void)os.write(buf,n); + (void)os.write(s,n); +} + void invalidFunctionArg_fesetexceptflag(fexcept_t* flagp, int excepts) { (void)std::fesetexceptflag(flagp, excepts);