user48730: I need to create a converter from epoch time stored in a time_t variable, to a struct tm variable, in order to check / create a certain task every hour or a day. This function should get also a past time_t for other uses.
Converting function, inside a library, works OK ( last two lines are for verification purposes, meaning conversion was done as expected ):
void myIOT32::convEpoch(time_t in_time, struct tm *convTime)
{
  convTime = gmtime(&in_time);
  char time_char[40];
  sprintf(time_char, "%04d-%02d-%02d %02d:%02d:%02d", convTime->tm_year + 1900, convTime->tm_mon+1, convTime->tm_mday,
            convTime->tm_hour, convTime->tm_min, convTime->tm_sec);

  Serial.print(" from funct: ");
  Serial.println(time_char);

Now, when calling it from my code and try to use time tm var, it causes the code to crash. In code below, I just try to print it to console:
void sendnewNotif()
{
  struct tm *newtime;
  time_t t=182423032;
  iot.convEpoch(t, newtime); // <--- Using the conversion
  char timeStamp[50];
  // Serial.print(newtime->tm_year); 

}

What may be the problem ? 
Guy

user7508: void myIOT32::convEpoch(time_t in_time, struct tm *convTime)
{
  convTime = gmtime(&in_time);

Here you are overwriting the parameter convTime. There is no point in
passing such a parameter if you are not going to use the value provided.
void sendnewNotif()
{
  struct tm *newtime;
  time_t t=182423032;
  iot.convEpoch(t, newtime); // <--- Using the conversion

newtime is initially uninitialized. The call to iot.convEpoch()
doesn't change that (the parameter is passed by value, not by
reference).
  Serial.print(newtime->tm_year);

This is dereferencing an uninitialized pointer, which is undefined
behavior and can crash the program.
The simplest solution I see is to have myIOT32::convEpoch() return the
pointer it got from gmtime(). Note that this points to static storage,
which makes the method not reentrant.
Example (not tested):
struct tm *myIOT32::convEpoch(time_t in_time)
{
  struct tm *convTime = gmtime(&in_time);
  // ...
  return convTime;
}

void sendnewNotif()
{
  time_t t = 182423032;
  struct tm *newtime = iot.convEpoch(t);
  Serial.print(newtime->tm_year); 
}


48730: <p>I need to create a converter from epoch time stored in a <code>time_t</code> variable, to a <code>struct tm</code> variable, in order to check / create a certain task every hour or a day. This function should get also a past <code>time_t</code> for other uses.</p>

<p>Converting function, inside a library, works OK ( last two lines are for verification purposes, meaning conversion was done as expected ):</p>

<pre><code>void myIOT32::convEpoch(time_t in_time, struct tm *convTime)
{
  convTime = gmtime(&amp;in_time);
  char time_char[40];
  sprintf(time_char, "%04d-%02d-%02d %02d:%02d:%02d", convTime-&gt;tm_year + 1900, convTime-&gt;tm_mon+1, convTime-&gt;tm_mday,
            convTime-&gt;tm_hour, convTime-&gt;tm_min, convTime-&gt;tm_sec);

  Serial.print(" from funct: ");
  Serial.println(time_char);
</code></pre>

<p>Now, when calling it from my code and try to use time <code>tm</code> var, it causes the code to crash. In code below, I just try to print it to console:</p>

<pre><code>void sendnewNotif()
{
  struct tm *newtime;
  time_t t=182423032;
  iot.convEpoch(t, newtime); // &lt;--- Using the conversion
  char timeStamp[50];
  // Serial.print(newtime-&gt;tm_year); 

}
</code></pre>

<p>What may be the problem ? </p>

<p>Guy</p>
 7508: <pre class="lang-cpp prettyprint-override"><code>void myIOT32::convEpoch(time_t in_time, struct tm *convTime)
{
  convTime = gmtime(&amp;in_time);
</code></pre>

<p>Here you are overwriting the parameter <code>convTime</code>. There is no point in
passing such a parameter if you are not going to use the value provided.</p>

<pre class="lang-cpp prettyprint-override"><code>void sendnewNotif()
{
  struct tm *newtime;
  time_t t=182423032;
  iot.convEpoch(t, newtime); // &lt;--- Using the conversion
</code></pre>

<p><code>newtime</code> is initially uninitialized. The call to <code>iot.convEpoch()</code>
doesn't change that (the parameter is passed by value, not by
reference).</p>

<pre class="lang-cpp prettyprint-override"><code>  Serial.print(newtime-&gt;tm_year);
</code></pre>

<p>This is dereferencing an uninitialized pointer, which is undefined
behavior and can crash the program.</p>

<p>The simplest solution I see is to have <code>myIOT32::convEpoch()</code> return the
pointer it got from <code>gmtime()</code>. Note that this points to static storage,
which makes the method not reentrant.</p>

<p>Example (not tested):</p>

<pre class="lang-cpp prettyprint-override"><code>struct tm *myIOT32::convEpoch(time_t in_time)
{
  struct tm *convTime = gmtime(&amp;in_time);
  // ...
  return convTime;
}

void sendnewNotif()
{
  time_t t = 182423032;
  struct tm *newtime = iot.convEpoch(t);
  Serial.print(newtime-&gt;tm_year); 
}
</code></pre>
