MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / valueFlowUninit

Method valueFlowUninit

test/testvalueflow.cpp:5912–6325  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5910 }
5911
5912 void valueFlowUninit() {
5913 const char* code;
5914 std::list<ValueFlow::Value> values;
5915
5916 code = "void f() {\n"
5917 " int x;\n"
5918 " switch (x) {}\n"
5919 "}";
5920 values = tokenValues(code, "x )");
5921 ASSERT_EQUALS(true, values.size()==1U && values.front().isUninitValue());
5922
5923 code = "void f() {\n"
5924 " const C *c;\n"
5925 " if (c->x() == 4) {}\n"
5926 "}";
5927 values = tokenValues(code, "c .");
5928 ASSERT_EQUALS(true, values.size()==1U && values.front().isUninitValue());
5929
5930 code = "void f() {\n"
5931 " C *c;\n"
5932 " if (c->x() == 4) {}\n"
5933 "}";
5934 values = tokenValues(code, "c .");
5935 ASSERT_EQUALS(true, values.size()==1U && values.front().isUninitValue());
5936
5937 code = "void f() {\n"
5938 " int **x;\n"
5939 " y += 10;\n"
5940 " x = dostuff(sizeof(*x)*y);\n"
5941 "}";
5942 ASSERT_EQUALS(0U, tokenValues(code, "x )").size());
5943
5944 // initialization
5945 code = "int foo() {\n"
5946 " int x;\n"
5947 " *((int *)(&x)) = 12;\n"
5948 " a = x + 1;\n"
5949 "}";
5950 values = tokenValues(code, "x +");
5951 ASSERT_EQUALS(true, values.empty());
5952 // ASSERT_EQUALS(1U, values.size());
5953 // ASSERT(values.front().isIntValue());
5954 // ASSERT_EQUALS(12, values.front().intvalue);
5955
5956 code = "struct AB { int a; };\n" // 11767
5957 "void fp(void) {\n"
5958 " struct AB ab;\n"
5959 " *((int*)(&(ab.a))) = 1;\n"
5960 " x = ab.a + 1;\n" // <- not uninitialized
5961 "}\n";
5962 values = tokenValues(code, "ab . a +");
5963 ASSERT_EQUALS(0, values.size());
5964 // ASSERT_EQUALS(1U, values.size());
5965 // ASSERT(values.front().isIntValue());
5966 // ASSERT_EQUALS(1, values.front().intvalue);
5967
5968 // #8036
5969 code = "void foo() {\n"

Callers

nothing calls this directly

Calls 4

frontMethod · 0.80
isPossibleMethod · 0.80
sizeMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected