Skip to content

Commit

Permalink
Test #12514: FN uninitvar with conditional write in subfunction
Browse files Browse the repository at this point in the history
  • Loading branch information
orbitcowboy committed Apr 10, 2024
1 parent bca43c2 commit 1210fa8
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 5 deletions.
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;
}

0 comments on commit 1210fa8

Please sign in to comment.