Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test #12514: FN uninitvar with conditional write in subfunction #6267

Closed
wants to merge 1 commit into from
Closed
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: 1 addition & 1 deletion test/cfg/std.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ void bufferAccessOutOfBounds_std_ifstream_get(std::ifstream& in, std::streambuf&
in.getline(cBuf, 100, 'a');

in.get(sb, 'a');

in.close();
}

Expand Down
22 changes: 22 additions & 0 deletions test/testuninitvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4350,6 +4350,28 @@ class TestUninitVar : public TestFixture {
" f(i);\n"
"}");
ASSERT_EQUALS("", errout_str());

valueFlowUninit("int f(int& i, int j, int k) {\n" // #12514
" if (k)\n"
" i = 2;\n"
" return i + j;\n"
"}\n"
"int main() {\n"
" int i;\n"
" return f(i, 1, 0);\n"
"}");
ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:4]: (warning) Uninitialized variable: i\n", errout_str());

valueFlowUninit("int f(int& i, int k) {\n"
" if (k)\n"
" i = 2;\n"
" return i;\n"
"}\n"
"int main() {\n"
" int i;\n"
" return f(i, 0);\n"
"}");
ASSERT_EQUALS("[test.cpp:8] -> [test.cpp:4]: (warning) Uninitialized variable: i\n", errout_str());
}

void uninitStructMember() { // struct members
Expand Down
2 changes: 1 addition & 1 deletion tools/defines/float.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "stdio.h"

#define PRINT_DEF(d, f) \
fprintf(stdout, ";"#d"=%"#f, d)
fprintf(stdout, ";"#d "=%"#f, d)

int main(void)
{
Expand Down
2 changes: 1 addition & 1 deletion tools/defines/limits.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "stdio.h"

#define PRINT_DEF(d, f) \
fprintf(stdout, ";"#d"=%"#f, d)
fprintf(stdout, ";"#d "=%"#f, d)

int main(void)
{
Expand Down
4 changes: 2 additions & 2 deletions tools/defines/stdint.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "stdio.h"

#define PRINT_DEF(d, f) \
fprintf(stdout, ";"#d"=%"#f, d)
fprintf(stdout, ";"#d "=%"#f, d)

#define PRINT_DEF_N(d1, d2, f) \
do { \
Expand Down Expand Up @@ -40,5 +40,5 @@ int main(void)
PRINT_DEF(WINT_MIN, d);
PRINT_DEF(WINT_MAX, d);

return 0;
return 0;
}
Loading