Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Program runs correctly, but SIGSEGV (http://www.go4expert.com/forums/program-runs-correctly-sigsegv-t22376/)

arpanm 10Jun2010 14:41

Program runs correctly, but SIGSEGV
 
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 10Jun2010 19:10

Re: Program runs correctly, but SIGSEGV
 
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 10Jun2010 19:14

Re: Program runs correctly, but SIGSEGV
 
hi,
thanks!!
But i got the solution.

kind Regards

arpanm 10Jun2010 19:15

Re: Program runs correctly, but SIGSEGV
 
Problem solved!!


All times are GMT +5.5. The time now is 01:54.