Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
==3768== Invalid read of size 2
==3768== at 0x4C59FE1: getenv (getenv.c:90)
==3768== by 0x4C8F21D: __libc_message (libc_fatal.c:67)
==3768== by 0x4D140F4: __fortify_fail (fortify_fail.c:32)
==3768== by 0x4D140A6: __stack_chk_fail (stack_chk_fail.c:29)
==3768== by 0x804C2E0: OutTrans (HResults.c:1092)
==3768== by 0x2020201F: ???
==3768== Address 0x20202020 is not stack'd, malloc'd or (recently) free'd
==3768==
==3768==
==3768== Process terminating with default action of signal 11 (SIGSEGV)
==3768== Access not within mapped region at address 0x20202020
==3768== at 0x4C59FE1: getenv (getenv.c:90)
==3768== by 0x4C8F21D: __libc_message (libc_fatal.c:67)
==3768== by 0x4D140F4: __fortify_fail (fortify_fail.c:32)
==3768== by 0x4D140A6: __stack_chk_fail (stack_chk_fail.c:29)
==3768== by 0x804C2E0: OutTrans (HResults.c:1092)
==3768== by 0x2020201F: ???
==3768== If you believe this happened as a result of a stack
==3768== overflow in your program's main thread (unlikely but
==3768== possible), you can try to increase the size of the
==3768== main thread stack using the --main-stacksize= flag.
==3768== The main thread stack size used in this run was 8388608.
==3768==
==3768== HEAP SUMMARY:
==3768== in use at exit: 1,036,774 bytes in 72 blocks
==3768== total heap usage: 236 allocs, 164 frees, 4,462,990 bytes allocated
==3768==
==3768== LEAK SUMMARY:
==3768== definitely lost: 0 bytes in 0 blocks
==3768== indirectly lost: 0 bytes in 0 blocks
==3768== possibly lost: 0 bytes in 0 blocks
==3768== still reachable: 1,036,774 bytes in 72 blocks
==3768== suppressed: 0 bytes in 0 blocks
==3768== Reachable blocks (those to which a pointer was found) are not shown.
==3768== To see them, rerun with: --leak-check=full --show-reachable=yes
==3768==
==3768== For counts of detected and suppressed errors, rerun with: -v
==3768== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 13 from 6)
Segmentation fault
its hinting towards line 1092 in the C src. The error may have originated elsewhere, but that's where it failed.
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.
I 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.
I 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) */
void AppendCell(int i, int j, char *tb, char *rb)
{
char *rlab,*tlab;
LabId rid=NULL,tid=NULL;
char empty[1];
if (i<0 || j<0)
HError(3391,"AppendCell: Trace back failure");
empty[0] = '\0'; rlab = tlab = empty;
switch (grid[i][j].dir) {
case DIAG:
tid = lTest[i]; tlab = tid->name;
rid = lRef[j]; rlab = rid->name;
AppendCell(i-1,j-1,tb,rb); break;
case HOR:
tid = lTest[i]; tlab = tid->name;
rid = NULL; rlab = empty;
AppendCell(i-1,j,tb,rb); break;
case VERT:
tid = NULL; tlab = empty;
rid = lRef[j]; rlab = rid->name;
AppendCell(i,j-1,tb,rb); break;
case NIL:
return;
}
if (tid != nulClass && rid != nulClass)
AppendPair(rb,rlab,tb,tlab);
}
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.