locked
error C4703, potentially uninitialized local pointer variable used

    Question

  • I am building mesa 8.0.4 on Windows 8 with VS2012 express and have a couple of compiler errors. One type of them is

    error C4703, potentially uninitialized local pointer variable 'iter' used

    This error occurs at line 6916 of ${MESASRC}\src\glu\sgi\libutil\mipmap.c. The variable iter is declared as

       const GLubyte *iter;
    

    I can fix this error by initializing this variable like

       const GLubyte *iter=NULL;
    
    I wonder why the C++ compiler in VS2012 is so critical? It might be a warning instead of an error.
    Friday, August 24, 2012 3:20 PM

Answers

  • The recommended practice is to leave the warnings on and to fix the code rather than to ignore or suppress the warnings.

    C4703 is a warning, not an error. The SDL Checks option tells the compiler to treat warnings associated with security issues as errors. You can treat all warnings as errors with the /WX flag.

    These checks make it easier to write good code: they allow the compiler to help detect problems that you don't want to leave in your code. SDL requires the 4700 series warnings be fixed because uninitialized pointers can lead to security errors. See the SDL Process docs, Appendix E.

    If you turn this off then you will need to go to extra effort to confirm that your code is correct since the compiler won't be helping find likely errors. If you are depending on legacy code which you can't reasonably fix, and if you have validated that the actual usage is safe then you can disable individual warnings with the /wd compiler flag.

    By far the best course would be to fix the code not to generate the warning rather than suppressing or ignoring the warning.

    --Rob

    • Marked as answer by Leonard Monday, August 27, 2012 9:33 AM
    Monday, August 27, 2012 6:52 AM
    Owner

All replies

  • After some search, I find this compiler error can be disabled by turnning off SDL check (/sdl-). Will turning off SDL check break my app's metro compatibiliy?
    Saturday, August 25, 2012 1:30 PM
  • The recommended practice is to leave the warnings on and to fix the code rather than to ignore or suppress the warnings.

    C4703 is a warning, not an error. The SDL Checks option tells the compiler to treat warnings associated with security issues as errors. You can treat all warnings as errors with the /WX flag.

    These checks make it easier to write good code: they allow the compiler to help detect problems that you don't want to leave in your code. SDL requires the 4700 series warnings be fixed because uninitialized pointers can lead to security errors. See the SDL Process docs, Appendix E.

    If you turn this off then you will need to go to extra effort to confirm that your code is correct since the compiler won't be helping find likely errors. If you are depending on legacy code which you can't reasonably fix, and if you have validated that the actual usage is safe then you can disable individual warnings with the /wd compiler flag.

    By far the best course would be to fix the code not to generate the warning rather than suppressing or ignoring the warning.

    --Rob

    • Marked as answer by Leonard Monday, August 27, 2012 9:33 AM
    Monday, August 27, 2012 6:52 AM
    Owner