How to ignore uninitialized variable error in MSVC

10,329

Solution 1

I suspect you're passing the compiler the /sdl option, which tells it to treat a 4703 (and various other things) as an error rather than a warning.

In the context of being paranoid about security it makes sense to treat this as an error - the compiler can't prove that what you're doing is safe, so it won't let the code through. If you don't want that, turn off /sdl.

Solution 2

There is checkbox for SDL checks when you create new project (wizard) in visual Studio 2015. If this is enabled, Visual Studio will report uninitialized variables as warning as part of potential other things, more info here.

If you already have a project with SDL checks on, you can disable it from project properties like in screen shot below. This way you don't have to deal with changing any command line arguments.

enter image description here

Share:
10,329
Admin
Author by

Admin

Updated on June 26, 2022

Comments

  • Admin
    Admin almost 2 years

    I'm having problems with MSVS compiler, I have the following code:

    if (!list) {
        *type = raw_data[*i++];
        ptr = (char*) &size;
        ptr[1] = raw_data[*i++];
        ptr[0] = raw_data[*i++];
        name = new char[size+1];
        memcpy (name, raw_data+*i, size);
        name[size] = '\0';
        *i += size;
    }
    

    And later:

    if (!list) {
        s->name = name;
        s->name_size = size;
    }
    

    The value of list doesn't change in this function, however I can't compile the code because of this error:

    Error 1 error C4703: potentially uninitialized local pointer variable 'name' used

    I find it incredibly annoying that this isn't a warning but an error. Changing the bool to const bool doesn't help either. Does someone know how to ignore this specific error in Visual Studio, but still show other errors/warnings?