Disable Run-Time Check Failure #3 for a method

I have some code that's triggering Run-Time Check Failure #3, but the variable should be assigned before use.

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
typedef const char *Id;

Id dialogueParentId = dialogue->Attribute("IdRef");
vector<Id> connectsTo = connections.at(dialogueParentId);
Id firstId;
for(const auto &ct : connectsTo)
{
    if(!dialogueChildren.count(ct))
	continue;
    firstId = ct;
}

const char *idRef = dialogue->Attribute("IdRef");
const char *type = dialogue->Attribute("Type");
const Dialogue d(idRef, type, firstId);
Dialogues.emplace(d, dialogueChildren);


On Clang and GCC this doesn't cause any issues. Is there anyway to just tell MSVC to ignore Run-Time Check Failure #3, for this method? firstId should always be assigned in that for loop. Does this involve the fact MSVC seems to think the range based iterator is incorrectly thought to be const int &, instead of const char *const?

EDIT: I'm using CLion CMake based build and not Visual Studio, so the project settings for this aren't in a menu.
Last edited on
"Run-Time Check Failure #3- The variable 'firstId' is being used without being initialized."
is generated after a check is performed at run-time.
It is a clear indication that the variable was never initialised / assigned a value.

In the posted code, the variable would remain uninitialised if:
a. connectsTo.empty() is true
b. for every ct in connectsTo, dialogueChildren.count(ct) == 0

Initialise firstId on line 5 with a default value.
eg. Id firstId = nullptr ; or Id firstId = "nothing" ;
Turns out I just needed to map a comparator for const char * to dialogueChildren.
Topic archived. No new replies allowed.