jeudi 24 mai 2018

Getting Warning C6385 if try to use function

I get this warning if I try to use function geti() in the following code.

Warning C6385   Reading invalid data from 'snapPts':  the readable size is '((geti()+1))*sizeof(DPoint3d)' bytes, but '48' bytes may be read.

But If I use integer like

int i

directly then I am not able to get the warning. I am unable to understand the scenario that what’s happening there, I googled it much but couldn’t find the solution. I am new to c++, please pardon me for spell mistake and please help me to understand this.

I am using the following code

#include <windows.h>  
#include <stdio.h>  
#include <malloc.h>
#include <corecrt_wstring.h>

int geti() {
return 2;
}
struct  DPoint3d
{
//! x coordinate
double x;
//! y coordinate
double y;
//! z coordinate
double z;
};

int main(array<System::String ^> ^args)
{

int i = 2;


if (i > 1) {

    DPoint3d*   snapPts = (DPoint3d *)_alloca((geti() + 1) * sizeof(DPoint3d));

    DPoint3d* snapPts2 = new DPoint3d();

    *snapPts2 = snapPts[1];


}

return 0;
}

A great answer is really appreciated.

Thanks

Aucun commentaire:

Enregistrer un commentaire