Reputation:
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?
Upvotes: 10
Views: 14248
Reputation: 12227
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.
Upvotes: 11
Reputation: 18964
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
.
Upvotes: 13