Is the following going to cause problems?
my_func()
{
char date_field[11];
time_t current_time;
time(¤t_time);
sprintf(date_field, "%0.3d%0.3d%.02d%0.2d\0", current_time.tm_yday,
current_time.tm_year, current_time.tm_hour, current_time.tm_min);
...
}
I realize that this may overrun the date_field buffer... What I'm concerned about is the side effect of this occurring? I.e.: a core dump? How to trap/catch this kind of issue?
\0becausesprintfdoes this for you.snprintfwhich will both guarantee the null and guarantee to never overrun?current_time.tm_yday % 1000etc. Also use%uformat then you won't get unexpected-signs.sprintf(if it has not already crashed), which must be, at most, one less than the buffer size.time_t current_time;andcurrent_time.tm_ydayis not valid C code.