C++ 0xC0000005:访问冲突读取位置0x00000000 hashfunc

C++ 0xC0000005:访问冲突读取位置0x00000000 hashfunc,c++,C++,我正在尝试执行我的程序并收到此错误消息 这是我的主菜 int numofsect=2; unsigned char** hash_table; hash_table = new unsigned char*[numofsect]; for (int i=0; i < numofsect; i++) hash_table[i] = new unsigned char[CryptoPP::SHA::DIGESTSIZE]; char** tab; tab = new char*[num

我正在尝试执行我的程序并收到此错误消息 这是我的主菜

int numofsect=2;
unsigned char** hash_table;
hash_table = new unsigned char*[numofsect];
for (int i=0; i < numofsect; i++)
    hash_table[i] = new unsigned char[CryptoPP::SHA::DIGESTSIZE];
char** tab;
tab = new char*[numofsect];
for (int i=0; i< numofsect; i++)
    tab[i] = new char[5];
int* tabsize;
tabsize = new int[2];
tabsize[0]=5;
tabsize[1]=5;

printf("Type sections:\n");
printf("Sect1: ");
scanf("%s", tab[0]);
printf("\nSect2: ");
scanf("%s", tab[1]);
hasher(numofsect, tab, tabsize, hash_table);
printf("Your hashed tab is:\n");
printf("hash sect1: ");
printf("%s",hash_table[0]);
printf("\nhash sect2: ");
printf("%s",hash_table[1]);

delete[] hash_table;
delete[] tab;
delete[] tabsize;
这里是我的哈希函数:

void hasher (int num_of_sect, char** sect_tab, int* size_of_sect_tab, unsigned char** hash_tab )
{
  for (int i=0 ; i<=num_of_sect ; i++) { // i is the number of each secion
    byte haSha1[CryptoPP::SHA::DIGESTSIZE]; //Byte table to calculate the hash of the section i
    byte* chaine = (byte*)malloc(sizeof(byte)*size_of_sect_tab[i]); //chaine reiceive the byte stream of the section i
    for (int j=0 ; j<size_of_sect_tab[i]; j++) //j is the n-th byte of the section
        chaine[j]=sect_tab[i][j]; //copy each byte of the sect_tab in the chaine


    CryptoPP::SHA().CalculateDigest(haSha1, chaine, size_of_sect_tab[i]); //Hash the section and return it in haSha1
    for (int j=0; j<CryptoPP::SHA::DIGESTSIZE; j++) //j is the n-th byte of the hashed section
        hash_tab[i][j]=haSha1[j]; //copy each byte of the hash to the hash_table
  }
}

感谢您的帮助

在以下代码中,当i=num\u of_sect时,您正在访问您的sect\u选项卡数组的边界之外:

 chaine[j]=sect_tab[i][j];
你不可能

for (int i=0 ; i<=num_of_sect ; i++) {
因为您传递了tab=newchar*[numofsect]


请记住,数组的索引范围是从0到size-1。

哈希函数中的for循环不应该是空的。如果要在某个地方解引用包含NULL的指针,请使用调试器…我认为它的for int I=0;错误发生在哪一行?
  for (int i=0 ; i < num_of_sect ; i++)