From 086ea79aeaa48d1fc22e62a1dcb0452257aea9db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Tue, 14 Jul 2026 11:45:41 +0200 Subject: [PATCH 1/2] add test --- test/testio.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/testio.cpp b/test/testio.cpp index f90773d4cf4..1e1b4abee3b 100644 --- a/test/testio.cpp +++ b/test/testio.cpp @@ -693,6 +693,23 @@ class TestIO : public TestFixture { " fwrite(X::data(), sizeof(char), buffer.size(), d->file);\n" "}"); ASSERT_EQUALS("[test.cpp:9:5]: (error) Read and write operations without a call to a positioning function (fseek, fsetpos or rewind) or fflush in between result in undefined behaviour. [IOWithoutPositioning]\n", errout_str()); + + check("struct MemStream {\n" + " char buf[1024];\n" + " int pos = 0;\n" + " void fwrite(const void *ptr, size_t n) { memcpy(buf + pos, ptr, n); pos += (int)n; }\n" + "};\n" + "struct FileStream {\n" + " FILE *fp;\n" + " size_t _fread(void *ptr, size_t n) { return ::fread(ptr, 1, n, fp); }\n" + " size_t fread(void *ptr, size_t n) { return _fread(ptr, n); }\n" + " void copy_to(MemStream *dst, size_t n) {\n" + " char tmp[256];\n" + " fread(tmp, n);\n" + " dst->fwrite(tmp, n);\n" + " }\n" + "};\n"); + ASSERT_EQUALS("", errout_str()); } void seekOnAppendedFile() { From 6923bd1cd2a1dd51e5bb1c13817b1dd876c2a865 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Tue, 14 Jul 2026 11:42:48 +0200 Subject: [PATCH 2/2] fix --- lib/checkio.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/checkio.cpp b/lib/checkio.cpp index 3d82bdb796a..0f4949272e8 100644 --- a/lib/checkio.cpp +++ b/lib/checkio.cpp @@ -155,6 +155,8 @@ void CheckIOImpl::checkFileUsage() tok = tok->linkAt(1); continue; } + if (tok->function() && tok->function()->nestedIn) + continue; if (tok->str() == "{") indent++; else if (tok->str() == "}") {