Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/checkio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() == "}") {
Expand Down
17 changes: 17 additions & 0 deletions test/testio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Loading