<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">

<head>
<meta http-equiv=Content-Type content="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 12 (filtered medium)">
<style>
<!--
 /* Font Definitions */
 @font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
        {font-family:Monaco;
        panose-1:0 0 0 0 0 0 0 0 0 0;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.apple-tab-span
        {mso-style-name:apple-tab-span;}
span.apple-style-span
        {mso-style-name:apple-style-span;}
span.EmailStyle19
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page Section1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.Section1
        {page:Section1;}
-->
</style>
<!--[if gte mso 9]><xml>
 <o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
 <o:shapelayout v:ext="edit">
  <o:idmap v:ext="edit" data="1" />
 </o:shapelayout></xml><![endif]-->
</head>

<body lang=EN-US link=blue vlink=purple style='word-wrap: break-word;
-webkit-nbsp-mode: space;-webkit-line-break: after-white-space'>

<div class=Section1>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>This is a bug that happened to me a while back. The reason that
the bug is so hard to find is because it errors out on code that did not cause
it. I&#8217;m being a bit vague. To be more specific, what happened to me was
that an earlier instruction &#8220;segfaulted&#8221; BUT there was no error
thrown until the random insertion of some line. When I say segfaulted earlier
that could be one of numerous things. 1. You went out of bounds on memory that
was given to you. 2. You tried to write to some ptr whose value got screwed up
and now you&#8217;re writing to some potentially deadly place in memory. 3. You
try and free a ptr that has been offset (I think that the last one does this,
but Im not sure).<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>Hope this help&#8230;at least a bit.<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'>-Ofer<o:p></o:p></span></p>

<p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p>&nbsp;</o:p></span></p>

<div>

<div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in'>

<p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span></b><span
style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>
ee122-bounces@ICSI.Berkeley.EDU [mailto:ee122-bounces@ICSI.Berkeley.EDU] <b>On
Behalf Of </b>Drew Lustro<br>
<b>Sent:</b> Wednesday, October 31, 2007 2:22 AM<br>
<b>To:</b> ee122@ICSI.Berkeley.EDU<br>
<b>Subject:</b> [ee122] Segfault Madness (need expert)<o:p></o:p></span></p>

</div>

</div>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>This may be one of the most difficult to explain problems,
but I'll try. &nbsp;I've been working on the server and everything was OK and
then I started getting segfaults. I was confused since the recent changes did
NOT involve any malloc'ing / freeing of any sort! After some tedious, tedious
commenting and uncommenting (because Eclipse's debugger was totally useless), I
found that if I uncomment a single declaration, the segfaults vanish.<o:p></o:p></p>

<div>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

</div>

<div>

<p class=MsoNormal>I added this BOOL declaration line to the top of <b>processClientInput(</b>client):<o:p></o:p></p>

<div>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

</div>

<div>

<div>

<p class=MsoNormal><span style='font-size:8.5pt;font-family:"Monaco","serif";
color:#7F0055'>int</span><span style='font-size:8.5pt;font-family:"Monaco","serif"'>
processClientInput(<span style='color:#005032'>sockAndBufs</span> &amp;client)<o:p></o:p></span></p>

</div>

<div>

<p class=MsoNormal><span style='font-size:8.5pt;font-family:"Monaco","serif"'>{<o:p></o:p></span></p>

</div>

<div>

<p class=MsoNormal><span class=apple-tab-span><span style='font-size:8.5pt;
font-family:"Monaco","serif"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span
style='font-size:8.5pt;font-family:"Monaco","serif";color:#7F0055'>int</span><span
style='font-size:8.5pt;font-family:"Monaco","serif"'> bytes =
consumeRequestLine(client);<o:p></o:p></span></p>

</div>

<div>

<p class=MsoNormal><span class=apple-tab-span><span style='font-size:8.5pt;
font-family:"Monaco","serif"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span
style='font-size:8.5pt;font-family:"Monaco","serif";color:#7F0055'>char</span><span
style='font-size:8.5pt;font-family:"Monaco","serif"'> ** uri;<o:p></o:p></span></p>

</div>

<div>

<p class=MsoNormal><span class=apple-tab-span><span style='font-size:8.5pt;
font-family:"Monaco","serif"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span
style='font-size:8.5pt;font-family:"Monaco","serif";color:#7F0055'>char</span><span
style='font-size:8.5pt;font-family:"Monaco","serif"'> * uri_string;<o:p></o:p></span></p>

</div>

</div>

<div>

<p class=MsoNormal><span class=apple-tab-span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>&nbsp;&nbsp;&nbsp;<span
class=apple-style-span><span style='font-size:8.5pt;font-family:"Monaco","serif";
color:#7F0055'>bool</span></span><span class=apple-style-span><span
style='font-size:8.5pt;font-family:"Monaco","serif"'> keepAlive = <span
style='color:#7F0055'>false</span>; // THIS, OF ALL THINGS IS WHAT CAUSES THE
SEGFAULTING</span></span><o:p></o:p></p>

</div>

<div>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

</div>

<div>

<p class=MsoNormal><span class=apple-tab-span><span style='font-size:8.5pt;
font-family:"Monaco","serif"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span
class=apple-style-span><span style='font-size:8.5pt;font-family:"Monaco","serif"'>//
... tons more code</span></span><o:p></o:p></p>

</div>

<div>

<p class=MsoNormal><span class=apple-tab-span><span style='font-size:8.5pt;
font-family:"Monaco","serif"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span
class=apple-style-span><span style='font-size:8.5pt;font-family:"Monaco","serif"'>//
note: uri and uri_string do involve mallocing, but did not give me any trouble
in the past</span></span><o:p></o:p></p>

</div>

<div>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

</div>

<div>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

</div>

<div>

<p class=MsoNormal><span class=apple-style-span><span style='font-size:8.5pt;
font-family:"Monaco","serif"'>Can any C/C++ Guru shed some light on this? Why
would commenting out the &quot;bool&quot; line lead to no segfaulting? Such an
obscure problem is throwing me off so hard that I'm starting to believe this
project is just a get-pissed-off-at-c project rather than us learning anything
new about socket programming.</span></span><o:p></o:p></p>

</div>

</div>

</div>

</body>

</html>