question

DanielShepherd-8507 avatar image
0 Votes"
DanielShepherd-8507 asked juhapartanen-5030 commented

how do i fix c26001

So, i am creating a console app DOS in visual studio 2019 until this in my code shows up:

 #include <string>
 #include <iostream>
    
 int main()
 {
     const int* firstrun = new int[1];
     std::string cmds = "cmds";
     if (firstrun[1] == '1') {
         std::cout << "loading MYDOS...\n";
         std::cout << "MYDOS has been loaded. type commands or help to start. \n";
         delete[] firstrun;
     }
     std::cin >> cmds;
     if (cmds == "about") {
         std::cout << "MYDOS version TEST-1.0 \n";
     }
     if (cmds == "help") {
         std::cout << "please refer to instructions on mydos.htm. \n";
     }
 }

    
 Warning    C6001    Using uninitialized memory '*firstrun'.    mydos_test1


How do i fix this! i have also referred to the help article. it did not help much.






c++
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

DanielShepherd-8507 avatar image
0 Votes"
DanielShepherd-8507 answered BarrySchwarz-8780 commented

never mind. it just randomly stopped getting the warning and started working.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Your code causes undefined behavior. One of the worst manifestations of undefined behavior is to sometimes do what you expect. It is perilous to assume that it will continue to do so.

0 Votes 0 ·
DanielShepherd-8507 avatar image
0 Votes"
DanielShepherd-8507 answered

this was actually c6001. my mistake.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

DavidLowndes-6766 avatar image
0 Votes"
DavidLowndes-6766 answered

const int* firstrun = new int[1];
if (firstrun[1] == '1')

You've only allocated 1 item, so firstrun[1] is immediately off the end!

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

DanielShepherd-8507 avatar image
0 Votes"
DanielShepherd-8507 answered DavidLowndes-6766 commented

im very new to c++ lol. does this mean i have to change that to a bigger number?

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I'm afraid your code didn't make a great lot of sense to me to be able to offer you anything more constructive.
You either need to allocate 2 items, or reference the 0'th (first) one.

0 Votes 0 ·