2014-01-09 1 views
-3

임 내 프로그램을 실행하고 여기 내 주요 여기가 0xc0000005 : 액세스 위반을 0x00000000 hashfunc

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; 

내 해시 FUNC이 오류 메시지 를받을려고 읽기 위치 : 당신의 도움

에 대한

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 
    } 
} 

감사합니다

+8

어딘가에서 NULL을 포함하는 포인터를 역 참조하면 디버거를 사용합니다 ... –

+1

나는 (int i = 0; i <= num_of_sect; i ++) { – drescherjm

+0

어떤 라인이 오류가 발생하나요? – Barmar

답변

2

다음 코드에서 i = num_of_sect 일 때 sect_tab 배열의 범위 밖에 있습니다.

chaine[j]=sect_tab[i][j]; 

당신은

for (int i=0 ; i<=num_of_sect ; i++) { 

을 가질 수 없습니다 당신이 탭 = 새 문자를 통과하기 때문에 * [numofsect]

배열의 인덱스는 0부터 1까지입니다.

+1

+1. 빠른 시일 내에. – SChepurin

0

귀하의 심부름 군 함수에서 루프 <= 그러나이 같은 단지 < 안 :

아마 문제의
for (int i=0 ; i < num_of_sect ; i++) 

. 디버거를 사용하여 단계별로 진행하면 문제가있는 곳을 곧 알 수 있습니다. 디버거는 가장 훌륭한 친구입니다!

0 기반 인덱스!

관련 문제