Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getenv helps prevent a segfault, very weird!

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
0
0
I've run into a very strange problem. I'm coding on the AIX platform, and for some reason, a function that I've written to access an SQL database has run into problems since I added a column to an xMotif table.<br><br>The table has three columns, the first is an ASCII character, the next is the ASCII code for that character, and the third column is the description of the character. In the SQL table, it only has the first and third column.<br><br>To investigate my problem, I created a function called ErrorFile, which logged entries and exits into and from functions. Upon the insertion of an ErrorFile call, the problem stopped.<br><br>Eventually I determined that it was segfaulting at the line &quot;XtVaSetValue(dlg-&gt;scr_table-&gt;table,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;XmNtopRow, 1,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;XmNrowCount, tb_data-&gt;count,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;XmNtableData, tb_data,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;NULL);<br><br>I suspect that the error is that tb_data has become corrupt.<br><br><br>If in one of the functions I add a call to getenv, it works, as long as the environment asked for is valid. (Well, actually I only know that getenv(); does not work)<br><br>It doesn't have to assign the environment to anything, nor does it have to be any particular envionment variable.<br><br>Does anyone have any idea why a getenv would help ANYTHING?
 
Its probably not that. Your compiler might be doing something naughty when it optimises your code. Try printing
out all of your variables before use or setting a flag
according to their value. Also strip out as much code as
you can so that your left with only the Xt statement.
I once had a problem in which a function would only work
if I added this
a = a;
if (a) {
value = 10 /a;
}

otherwise the compiler would optimise the check away and
do a divide by zero
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top