Click here to Skip to main content
15,669,039 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using VS2017 and do not understand why I am getting compiler "Warning C6001 Using uninitialized memory 'values'", on line if(values!= NULL) in catch block.

#include <windows.h>

typedef enum
   VALUE_STATE_ERROR         = 2,
   VALUE_STATE_VALID         = 3,
} XyzValueState_t;

class XyzValue
    private:    XyzValueState_t     _valueState;
    protected:  XyzValue( XyzValueState_t valueState )  {
                    _valueState = valueState;

typedef XyzValue* xyzValuePtr_t;

    bool flag=true;
    xyzValuePtr_t* values = NULL;
    unsigned int _argument=2;
    if(flag==true)  {
        values = new PCLValuePtr_t[2]{ NULL,NULL };
        try     {
            values[0] = new PCLUnsignedInteger(_argument);
            values[1] = new PCLUnsignedInteger(_argument);
            xyz(values);    // passing the value to third party function which returns void
        catch(...)  {
            if(values!= NULL){
                for(int k = 0; k < 1; k++)   {
                   delete values[k];
                   values[k] = NULL;
                delete [] values;
                values = NULL;

Thank you in advance for your help and guidance

What I have tried:

I have tried to put different try catch for Values[] initialization.
Updated 10-Jul-22 8:24am
CHill60 8-Jul-22 8:32am    
Don't put that stuff in the catch! The catch is there to deal with errors and all you are doing is hiding what the actual problem is. Remove the try-catch entirely and you should get an error message telling you what the root cause is
0x01AA 9-Jul-22 10:38am    
But the question remains (whether the code is good or bad), I don't see a reason for that warning. In case values = new PCLValuePtr_t[2]{ NULL,NULL }; fails, then 'try/catch' is out of question...
I don't see yet, what I'm missing
CPallini 8-Jul-22 8:48am    
You should post the actual code, in order to get better help. For instance, class XyzValue lacks of semicolon at the end and therefore would generate a compilation error.
Member 15627495 8-Jul-22 12:18pm    
as you encount a "warning" your software can compile and run with this flag up.
but at runtime error could appears and your app could crash.

when you do :
values[0] = new PCLUnsignedInteger(_argument);
values[1] = new PCLUnsignedInteger(_argument);

and one more thing values[0] == values[1] in your code

like CHil60 notify you, about "try and catch" , you might use it when a true risk is here ( like IO use with hard drives write and read, or networks working in loops ).

try statement is really:
do ; do ; do ;
exception 1 thrown if an error of type exception 1;
exception 2 ... ;
exception 3 ....;
you'll learn to have a good use of "try/catch"

in your code, I can't see where the default var is initialized with its TYPE.
0x01AA 9-Jul-22 10:29am    
I agree with you. I don't see a reason for that warning...
This because if values = new PCLValuePtr_t[2]{ NULL,NULL }; fails the 'catch' is out of question.
And thatwhy you don't even need to test if(values!= NULL) in 'catch'

1 solution

Not really a solution, but maybe a little help to confirm your doubts ...
In case the warning is really exactly on the line if(values!= NULL) in the catch block, I'm with you, I don't see a reason for that warning.

This because:
In case values = new PCLValuePtr_t[2]{ NULL,NULL }; fails, the try...catch... is out of question. And therefore we can assume in 'catch', that values is valid.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900