Compiler Warning (level 4) C4703
Visual Studio 2015
The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.
The latest version of this topic can be found at Compiler Warning (level 4) C4703.
Potentially uninitialized local pointer variable 'name' used
The local pointer variable name might have been used without being assigned a value. This could lead to unpredictable results.
The following code generates C4701 and C4703.
#include <malloc.h> void func(int size) { void* p; if (size < 256) { p = malloc(size); } if (p != nullptr) // C4701 and C4703 free(p); } void main() { func(9); }
c:\src\test.cpp(10) : warning C4701: potentially uninitialized local variable 'p' used c:\src\test.cpp(10) : warning C4703: potentially uninitialized local pointer variable 'p' used
To correct this warning, initialize the variable as shown in this example:
#include <malloc.h> void func(int size) { void* p = nullptr; if (size < 256) { p = malloc(size); } if (p != nullptr) free(p); } void main() { func(9); }
Compiler Warning (level 4) C4701
Warnings, /sdl, and improving uninitialized variable detection
Show: