Core dump error in code


 
Thread Tools Search this Thread
Top Forums Programming Core dump error in code
# 1  
Old 09-27-2011
Core dump error in code

HI,
I am getting run time error when am trying to compile the following coe can any one please help me
Code:
 while (fgets(strLine, MAX_LINELEN, vobjFile) != NULL && feof(vobjFile) == 0) {
                printf("this is the first loop\n");

                while (strcmp(strLine, "BEGINTRANS\n") != 0) 
                /*printf("this is second loop\n");
                if (fgets(strLine, MAX_LINELEN, vobjFile) == NULL)
                        break;
                if(!feof(vobjFile)) break;*/
                printf("second loop ends");
                while(strcmp(strLine, "ENDTRANS\n") != 0) {
                        printf("third loop\n");

                        _ParseReplyMessage(strLine, &objCountersInMessage);//This is the place iam getting an error
                        printf("this is the end\n");

And the code of this function is

Code:
static void _ParseReplyMessage(const char *vstrLine, CountersInMessage *robjCountersInMessage)
{
        static const char *strRoutine = "_ParseReplyMessage";
        char strHHMMSS[9] = "";
        char *strTransName;
        const char *tsstr;
        char strMSS[5] = "";

        _CountersInMessageInitialize(robjCountersInMessage);
        /*_FindTransactionDetails(vstrLine, &robjFindTransDetail);*/

        if(strstr(vstrLine, "NEWOLUF2") !=0)
                tsstr = strstr( vstrLine, "Input <");
                sscanf( tsstr, "Input <%8s", strTransName);
        strcpy(robjCountersInMessage->strTransactionName, strTransName);

        tsstr=strstr(vstrLine, "Timestamp");
        sscanf(tsstr, "Timestamp <%[^>]>", strHHMMSS);
        robjCountersInMessage->intTimestamp = _ConvertTimestamp(strHHMMSS);
        if (strncmp(vstrLine, "Elapsetime", 10) == 0)
                sscanf( vstrLine, "Elapsetime <%d>",&strMSS);

}

This function is getting the error core dump

Please help me Thanks in advance.

}

Last edited by pludi; 09-27-2011 at 04:35 AM..
# 2  
Old 09-27-2011
Look at the 2 statements below and it would make sense of the runtime error...
Code:
char *strTransName;  // this can hold 1 byte
...
sscanf( tsstr, "Input <%8s", strTransName);  // stuffing 8 bytes into a 1 byte holder??

# 3  
Old 09-28-2011
Data

Getting same error bus error(core dump ) at the same location please help me

Code:
while (fgets(strLine, MAX_LINELEN, vobjFile) != NULL && feof(vobjFile) == 0) {

                /* Only consider STL or BLANK messages */

                if((strcmp(strLine, "BEGINTRANS\n") != 0) && (strcmp(strLine, "ENDTRANS\n") != 0)) {
                                continue;
                        }

                        /* Decode a single line in file LOG.stq.stdout.DDMonYY */
                _ParseReplyMessage(strLine, &objCountersInMessage); //Getting the error here :wall:


And the code of this function is

Code:
static void _ParseReplyMessage(const char *vstrLine, CountersInMessage *robjCountersInMessage)
{
        static const char *strRoutine = "_ParseReplyMessage";
        char strHHMMSS[9] = "";
        char strTransName[100];
        const char *tsstr;
        int intMSS = -1;

        _CountersInMessageInitialize(robjCountersInMessage);
        /*_FindTransactionDetails(vstrLine, &robjFindTransDetail);*/
        printf("Initial stage\n");
        if(strstr(vstrLine, "NEWOLUF2") !=0)
                tsstr = strstr( vstrLine, "Input <");
                sscanf( tsstr, "Input <%8s", &strTransName);
        strcpy(robjCountersInMessage->strTransactionName[LEN_TRANS_NAME], strTransName);

        tsstr=strstr(vstrLine, "Timestamp");
        sscanf(tsstr, "Timestamp <%[^>]>", strHHMMSS);
        robjCountersInMessage->intTimestamp = _ConvertTimestamp(strHHMMSS);
        if (strncmp(vstrLine, "Elapsetime", 10) == 0)
                sscanf( vstrLine, "Elapsetime <%d>", &intMSS);
        robjCountersInMessage->intProcTime = intMSS;
      objCounterInMessage->intProcTime = intMSS;
 }

Please help me in finding it and what is the error means exactly in this programe and y it is coming like this.

Thank you in advance.

Moderator's Comments:
Mod Comment Video tutorial on how to use code tags in The UNIX and Linux Forums.

Last edited by radoulov; 10-06-2011 at 12:37 PM..
# 4  
Old 10-06-2011
Are you getting the error in the call to _ParseReplyMessage, or inside the function itself?

For the former, have you checked objCountersInMessage is not NULL? In the latter, is strHHMMSS always big enough to hold the timestamp?
# 5  
Old 10-06-2011
Quote:
Originally Posted by shamrock
Look at the 2 statements below and it would make sense of the runtime error...
Code:
char *strTransName;  // this can hold 1 byte

Incorrect -- it's a pointer to nowhere in particular, which can store nothing at all.

Try fprintf(stderr, "initial stage\n"); instead of printf("initial stage\n");. The stderr printf will got DIRECTLY to stdout with no buffering. printf() statements that already happened can be lost when your program crashes, but fprintf(stderr, ...); will never trick you that way.
# 6  
Old 11-10-2011
Your code faults:
1) Check all the pointers before using them (specially both the pointers your functions is getting as arguments).
2) Do Must check the strstr() return too; which you have not done; they return null when the pattern is not found but you used without looking at this.

To sum-up do proper error-handling in your code.
Further you can always look at the using gdb with crash dumps; it's easy to find issues.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. HP-UX

Core dump in HP-UX

Hi Guys, I was wondering if somebody could give me a link to a very good source of information or document about core dump process and How to's about it. I have also googled it and found some articles myself. Thanks Messi (1 Reply)
Discussion started by: messi777
1 Replies

2. Shell Programming and Scripting

Segmentation Fault(Core Dump) Error

Hi all, I have a folder with some 28 files. I have a script file that will iteratively take one file at a time from the folder and provide an output for the input file. Till the 7th file, there was no problem but from the 8th file onwards, i got this Segmentation Fault(Core Dump) error. A file... (2 Replies)
Discussion started by: mick_000
2 Replies

3. Shell Programming and Scripting

Unable to catch the output after core dump and bus error

I have a weird situation in which the binary dumps core and gives bus error. But before dumping the core and throwing the buss error, it gives some output. unfortunately I can't grep the output before core dump db2bfd -b test.bnd maxSect 15 Bus Error (core dumped) But if I do ... (4 Replies)
Discussion started by: rakeshou
4 Replies

4. AIX

Core dump

Hi , I want to read core dump file on AIX5.3. While i am trying to use following commands, i am getting only few lines of information. ux201p3:e46123> dbx capsWrkstnMgr core Type 'help' for help. reading symbolic information ... Segmentation fault in malloc_common.extend_brk at... (1 Reply)
Discussion started by: rps
1 Replies

5. Programming

core dump

how to view core dumped file using gdb and how to extract information from the coredumped file.can we get similar information from the other utilites like strace or ptrace. (2 Replies)
Discussion started by: Manabhanjan
2 Replies

6. UNIX for Advanced & Expert Users

Core Dump

Hello all, Iam new to unix while executing java program which finely working in windows know iam testing with unix ,but in unix while executing iam getting core dump, my application is in client server environment and it is menu drivrn application on clicking options no problem but after some time... (1 Reply)
Discussion started by: vinp
1 Replies

7. UNIX for Advanced & Expert Users

core dump

Hi All, i am new to this forum.i want detail of reading the core file and trace the problem because of what the program get crashed.please help me.if any body knows any website or tutoril plese let me know. sudhir (6 Replies)
Discussion started by: sudhir patnaik
6 Replies

8. Programming

about core dump

MY friends: my program under sco unix have a problem? it create a core dump file on the path when execute program , but i can't find the error of the C program ,i don't know how to see the error about my program use core, please help me or give me some suggest and what tools can use... (1 Reply)
Discussion started by: zhaohaizhou
1 Replies

9. UNIX for Dummies Questions & Answers

core dump

does any one have read a core dump? is there any reader for that? or may i know what is the use of that core which takes sometimes memory in GBs? :) (6 Replies)
Discussion started by: sskb
6 Replies

10. UNIX for Dummies Questions & Answers

help, what is the difference between core dump and panic dump?

help, what is the difference between core dump and panic dump? (1 Reply)
Discussion started by: aileen
1 Replies
Login or Register to Ask a Question