1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Program runs correctly, but SIGSEGV

Discussion in 'C' started by arpanm, Jun 10, 2010.

  1. arpanm

    arpanm New Member

    Joined:
    Jun 10, 2010
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    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
     
  2. jimblumberg

    jimblumberg New Member

    Joined:
    May 30, 2010
    Messages:
    120
    Likes Received:
    29
    Trophy Points:
    0
    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.
     
  3. arpanm

    arpanm New Member

    Joined:
    Jun 10, 2010
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    hi,
    thanks!!
    But i got the solution.

    kind Regards
     
  4. arpanm

    arpanm New Member

    Joined:
    Jun 10, 2010
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Problem solved!!
     

Share This Page