无法解决警告C6386



伙计们,我需要一些帮助。在写入"AnArray"时,我收到警告C6386缓冲区溢出:可写大小为"nrows*8"字节,但可能会写入"16"字节。在以下代码上

#include <math.h>
void SubMain(int, int);
int CSTEBit(int, int, int);
double Fact(int);
double Perm(int, int);
int Comb(int, int);
int main()
{
SubMain(13, 5);
}
void SubMain(int N, int R)
{
int** AnArray;
int nrows = Comb(N, R) + 1;
int ncolumns = 8;
int Pos;
int Count;
AnArray = new int* [nrows];
for (int i = 0; i < nrows; i++)
AnArray[i] = new int[ncolumns];
for (int a = 0; a < nrows; a++)
{
for (int b = 0; b <= 7; b++)
AnArray[a][b] = 0;
}

Pos = 0;
Count = 0;
do
{
Pos += 1;
if ((CSTEBit(3, AnArray[Pos][7], 4) == 0) && (CSTEBit(3, AnArray[Pos][7], 5) == 0))
Count += 1;
} while (Count != nrows - 1);
AnArray[Pos][7] = CSTEBit(1, AnArray[Pos][7], 4);
}
int CSTEBit(int CSTE, int Byt, int Bit)
{
int tempCSTEBit = 0;
if (Bit < 8)
{
int Mask = (int)pow(2, Bit);
switch (CSTE)
{
case 0:
tempCSTEBit = (int)(Byt && ~Mask);
break;
case 1:
tempCSTEBit = (int)(Byt | Mask);
break;
case 2:
tempCSTEBit = (int)(Byt ^ Mask);
break;
case 3:
if ((Byt & Mask) > 0)
{
tempCSTEBit = 1;
}
else
{
tempCSTEBit = 0;
}
break;
default:
tempCSTEBit = Byt;
break;
}
}
else
{
tempCSTEBit = Byt;
}
return tempCSTEBit;
}
double Fact(int N)
{
double tempFact = 0;
if (N <= 1)
{
tempFact = 1;
}
else
{
tempFact = N * Fact(N - 1);
}
return tempFact;
}
double Perm(int N, int R)
{
double tempPerm = 0;
int a = 0;
double b;
b = 1;
if (N < R)
{
tempPerm = 0;
}
else
{
for (a = (N - (R - 1)); a <= N; a++)
{
b = b * a;
}
tempPerm = b;
}
return tempPerm;
}
int Comb(int N, int R)
{
int tempComb = 0;
if (N < R)
{
tempComb = 0;
}
else
{
tempComb = (int)(Perm(N, R) / Fact(R));
}
return tempComb;
}

变量Pos永远不会高于Comb函数返回的用于初始化AnArray的值。提前感谢您的回答。

实际上,我在Pos+=1之后的do循环中插入了"if(Pos<nrows(";警告也消失了。

最新更新