Program runs correctly, but SIGSEGV

arpanm's Avatar, Join Date: Jun 2010
Newbie Member
Hi all,
My code is giving the desired o/p, but at the end its producing segmentation fault.
(I know this is very column and also I have checked other posts, but couldn't understand the solution)
Here is my code
Code:
#include <stdio.h> 
#include <stdlib.h> 
#include <string.h> 
#include <ctype.h> 
 
#include "blake.h" 
 
 
 
 
int    genShortMsg(int hashbitlen); 
 
 
 
int 
main() 
{ 
    int ret_val;
 
    ret_val = genShortMsg(256);
     
    return 0; 
     
} 
 
 
 
int  
genShortMsg(int hashbitlen) 
{ 
 
    int            msglen, msgbytelen; 
    BitSequence    Msg[7], MD[64]; 
 
        msglen=55;     
        msgbytelen = (msglen+7)/8; 
     
 
 
    int        ch, started; 
    BitSequence    ich; 
    int i; 
    if ( msgbytelen == 0 ) { 
        Msg[0] = 0x00; 
         
    } 
    memset(Msg, 0x00, msgbytelen); 
    started = 0; 
    char str[] = "14B06DD54EB364"; 
    int j; 
 
    for(j=0;j<strlen(str);j++){ 
        ch=str[j]; 
            if ( (ch >= '0') && (ch <= '9') ) 
                ich = ch - '0'; 
            else if ( (ch >= 'A') && (ch <= 'F') ) 
                ich = ch - 'A' + 10; 
             
            else if ( (ch >= 'a') && (ch <= 'f') ) 
                ich = ch - 'a' + 10; 
             
            for ( i=0; i<msgbytelen-1; i++ )Msg[i] = (Msg[i] << 4) | (Msg[i+1] >> 4); 
            Msg[msgbytelen-1] = (Msg[msgbytelen-1] << 4) | ich; 
 
    } 
          
     
        for(i=0;i<64;i++)MD[i]=0; 
     
         
        Hash(256, Msg, msglen, MD); 
     
        for(i=0;i<32;++i)printf("%02X",MD[i]);
 
        printf("\n");

 
    return 0; 
}
It prints correct o/p(computed by Hash(.......)), but crashes when genShortMsg() returns.

Thanks in advance for the reply
jimblumberg's Avatar
Ambitious contributor
Could you please provide a complete program that reproduces the error. The program you supplied is missing an include file and also the Hash function. I believe that your problem is in the Hash function.
arpanm's Avatar, Join Date: Jun 2010
Newbie Member
hi,
thanks!!
But i got the solution.

kind Regards
arpanm's Avatar, Join Date: Jun 2010
Newbie Member
Problem solved!!