localtime() - segmentation fault
<p>I have this code that return the week day from a date like "29-02-2016", but sometimes it gives me segmentation fault in localtime(&amp;t). </p>

<pre><code>int obterDiaSemana(char *str) {
 struct tm tm2;
 if(strptime(str, "%d-%m-%Y", &amp;tm2) != NULL) {
  time_t t = mktime(&amp;tm2);
  return localtime(&amp;t)-&gt;tm_wday; //Sunday=0, Monday=1, etc.
 }
 return -1;
}
</code></pre>

<p>the function receives:</p>

<pre><code> char userDate[10]="29-02-2016";
</code></pre>

<p>I've been looking for a solution but cant solve this. </p>

<p>Thanks in advance.</p>

<p>If you need some additional info just let me know.</p>