![]() |
segmentation fault bash script
When bash script is invoked it leaves the following
error message Calculating results for Mix - 1 ./06_hresult.sh: line 15: 2075 Segmentation fault 139 Calculating results for Mix - 2 ./06_hresult.sh: line 15: 2076 Segmentation fault 139 Calculating results for Mix - 4 ./06_hresult.sh: line 15: 2077 Segmentation fault 139 Calculating results for Mix - 8 ./06_hresult.sh: line 15: 2078 Segmentation fault 139 Calculating results for Mix - 16 ./06_hresult.sh: line 15: 2079 Segmentation fault 139 Calculating results for Mix - 32 ./06_hresult.sh: line 15: 2080 Segmentation fault 139 Calculating results for Mix - 64 ./06_hresult.sh: line 15: 2081 Segmentation fault 139 script Code:
#!/bin/bash64 bit RAM -1GB |
The segmentation fault occurs after the "Calculating results" text but before the echo $? statement. This only leaves one possibility: The "HResults" command in line 12, whatever that is.
|
valgrind says
Code:
==3768== Invalid read of size 2 |
Well here
Code:
==3768== by 0x804C2E0: OutTrans (HResults.c:1092)When I used to do C, SIGSEGV aka SIG 11 was usually caused by writing beyond the end of an array, often a 'string' array, overwriting the terminating \0. This could cause other data to be corrupted. Alternately, a subsequent read would read into the memory region beyond and crash. |
Code:
/* OutTrans: output aligned transcriptions using best path in grid */ |
Quote:
Which line is number 1092? |
Code:
no checking of output lengthI can't debug your code for you from here, but basically you need to check the size/len of all the vars mentioned there. It looks like the actual error will be in the AppendCell() fn (or a fn called from there...). OutTrans() itself doesn't do any var manipulation; just assigns start values and prints the results. |
Quote:
void OutTrans(void) { char refBuf[4096]; /* no checking of output length so */ char testBuf[4096]; /* these are generous sizes */ strcpy(refBuf," LAB: "); strcpy(testBuf," REC: "); AppendCell(nTest,nRef,testBuf,refBuf); printf("Aligned transcription: %s vs %s\n", labfn, recfn); printf("%s\n",refBuf); printf("%s\n",testBuf); fflush(stdout); } |
[QUOTE=chrism01;4874369]
Code:
no checking of output lengthI can't debug your code for you from here, but basically you need to check the size/len of all the vars mentioned there. It looks like the actual error will be in the AppendCell() fn (or a fn called from there...). OutTrans() itself doesn't do any var manipulation; just assigns start values and prints the results.[/QUOTE Thank you Chris for your value clues, reference ApppendCell() Code:
/* AppendCell: path upto grid[i][j] to tb and rb (recursive) */ |
It isn't the size guys - it is copying a total of 7 bytes.
The problem is more likely that these buffers are passed to another structure, and then stored. The buffers are on the stack, so when the function returns, anything that is pointing to them will be corrupted by other functions. Notice the function AppendCell - the parameters are tb and rb. These are the stacked 4k arrays passed to AppendPair... so does AppendPair happen to require heap allocated strings? If not, then there is no need for the 4k arrays - constant strings would work just as well, and save 8k of stack space as a benefit. |
| All times are GMT -5. The time now is 11:57 PM. |