Analyzers
Talk to fellow users of Intel Analyzer tools (Intel VTune™ Profiler, Intel Advisor)

How to understand 'Uninitialized memory access'?

Zhanghong_T_
Novice
615 Views

Dear all,

I have the following code:

...

    node *node3=new node[npoint];
    for (int i=0;i<npoint;i++)
    {
        node3.id=i;
        node3.x=doublearray[j++];
        node3.y=doublearray[j++];
        node3.z=doublearray[j++];
    }
    std::qsort(node3,npoint,sizeof(node),comparenode);

...

The Intel Inspector tells me the 'Uninitialized memory access' error at line

    node *node3=new node[npoint];

and qsort function.

How to understand this error? How to modify the code to remove this error message?

 

Thanks,

Zhanghong Tang

 

0 Kudos
3 Replies
Bernard
Valued Contributor I
615 Views

>>>The Intel Inspector tells me the 'Uninitialized memory access' error at line>>>

Uninitialized memory access means that pointer which is supposed to contain the valid address was not initialized(does not contain valid address) probably null or some junk.

>>> node *node3=new node[npoint];>>>

Did actually try to run your code? Does it crash?

The quoted example while disassembled node3 pointer to array of objects type node should contain the address to heap allocated memory. The size of node array is the size of npoint elements multiplied by the object type node size.

Btw, that message could be also false positive for example when you earlier initialized *node3 pointer to null and Inspector was not able to track the changes(call to new operator).

 

0 Kudos
Zhanghong_T_
Novice
615 Views

Hi iliyapolak,

Thank you very much for your kindly reply. The code doesn't crash. I just use Intel Inspector to check possible hidden problems of my code.

Do you mean that I should initialize the pointer like this?

for (int i=0;i<npoint;i++)node3=0;

but I think the 'new' operation has assigned address for every node3.

I think I have assigned values for every node3 after the 'new' operation. On the other hand, if I have the following code after the 'new' operation, the error message disappeared.

    memset(node3,0,npoint*sizeof(node));


but I don't think it is necessary since I have assigned values for every node3.

 

0 Kudos
Bernard
Valued Contributor I
615 Views

That is fine what you are doing . I also run strict rules code analysis from time to time.

I do not think that you need to initialize node array members to null. Operator new initialized *node3 pointer to point allocated heap memory.

IIRC at assembly level your objects are decomposed into primitive member variables (float,double) which are copied probably by vectorized mem copy function.

0 Kudos
Reply