JavaScript is not currently enabled, but is required for full CodeSonar manual search and browse functionality.
If you are viewing this file in your hub's Web GUI, enable JavaScript in your browser: you will also need it for GUI functionality.
If you opened this file directly from disk, your browser may be directly suppressing JavaScript functionality: certain browsers perform this suppression on local files (but not files delivered by web servers) for security reasons.
| CodeSonar® 9.2p0 | CONFIDENTIAL | CodeSecure Inc |
An attempt to use the value of a variable that has not been initialized.
When MOVED_FROM_UV_CHECK_ENABLED=Yes, this includes attempts to use the value of a variable that has been left in a moved-from state after applying a move constructor or move assignment (C++ code only).
Occurrences of uninitialized variables in dead code (code with no effect on program behavior under any circumstances) do not trigger warnings of this class.
| Class Name | Uninitialized Variable | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Significance | security | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Mnemonic | LANG.MEM.UVAR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Categories |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Availability | Available for C and C++. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Enabling | Checks for this warning class are enabled by
default. To disable them, add the following WARNING_FILTER rule to the
project configuration file.
WARNING_FILTER += discard class="Uninitialized Variable" |
#include <iostream> #include <utility> // Example 1: simple uninitialized variable void lang_mem_uvar_simple(void){ int i,j; int *p; std::cout << j << "\n"; // 'Uninitialized Variable' warning issued here // No warnings are issued in any of the following statements. // - Each of them is dead code: executing has no effect on program state, // even though i is not initialized. // - An optimizing compiler may remove any or all of these statements. i; i + 1; &p[i]; } // Example 2: uninitialized variable due to an object being left in // moved-from state. class C { private: int *p; public: C() =default; // Default constructor constexpr C(const C&) =default; // Copy constructor C(C && other) : p(std::move(other.p)){} // Move constructor constexpr C& operator=(const C&) =default; // Copy assignment int get(void){ return p ? *p : 0; // 'Uninitialized Variable' warning issued here // when MOVED_FROM_UV_CHECK_ENABLED=Yes } }; int useC(C c){return c.get();} int lang_mem_uvar_movefrom_C(C c){ int i = 0; i += c.get(); // ok : no program path in which c is in moved-from state i += useC(std::move(c)); // c moved-from i += c.get(); // Warning issued because c is used while // in moved-from state: warning endpoint // is in the C::get() definition above. c = C(); // c no longer moved-from i += c.get(); // ok: c not in moved-from state return i; }
The following configuration file parameters affect checks for this warning class.
To report problems with this documentation, please visit https://support.codesecure.com/.