title: Why a code that used to work fine can crash in C?
body: <p>I wrote a code that help extract a data from specific string.
  Example: if the String is &quot;ABCD*&quot;
  the code will help me define the index of the last char before &quot;*&quot;</p>
  <pre><code>char *magicchar;
  int IndexofMagicchar =0;
  magicchar=strchr(InputData,&quot;*&quot;);
  IndexofMagicchar = (int)(magicchar - InputData);
  </code></pre>
  <p>Now the code works fine until you use an InputData that does not contain a &quot;*&quot;then the service will crash.
  The fix was simply to add a simple test on the magicchar variable :</p>
  <pre><code>char *magicchar;
  int IndexofMagicchar =0;
  magicchar=strchr(InputData,&quot;*&quot;);
  if (magicchar!=NULL)            
      IndexofMagicchar = (int)(magicchar - InputData);
  </code></pre>
  <p>My question is that the code was working fine even if the Input does not contain a &quot;*&quot; why the crash become systematic ?</p>