Skip to content
Snippets Groups Projects
Commit 23e458f1 authored by Thomas Jahns's avatar Thomas Jahns :cartwheel:
Browse files

Limit range of values in print.

* Otherwise snprintf might truncate the output.
parent 787add30
No related branches found
No related tags found
2 merge requests!91Add alternative code path for huge buffers.,!89Miscellaneous fixes and CDI-PIO improvements
......@@ -271,10 +271,19 @@ addToDate(struct tm *me, long long amount, long unit)
static char *
makeDateString(struct tm *me)
{
const size_t length = 4 + 1 + 2 + 1 + 2 + 1 + 2 + 1 + 2 + 1 + 2 + 4 + 1;
char *result = (char *) Malloc(length);
snprintf(result, length, "%04d-%02d-%02dT%02d:%02d:%02d.000", me->tm_year + 1900, me->tm_mon + 1, me->tm_mday, me->tm_hour,
me->tm_min, me->tm_sec);
enum { size = 4 + 1 + 2 + 1 + 2 + 1 + 2 + 1 + 2 + 1 + 2 + 4 + 1 };
char *result = Malloc(size);
assert(me->tm_year + 1900 < 10000 && me->tm_year + 1900 > -1000
&& me->tm_mon >= 0 && me->tm_mon < 12
&& me->tm_mday >= 1 && me->tm_mday <= 31
&& me->tm_hour >= 0 && me->tm_hour <= 24
&& me->tm_min >= 0 && me->tm_min < 60
&& me->tm_sec >= 0 && me->tm_sec <= 60);
int year = me->tm_year + 1900;
if (year > 10000) year = 9999;
else if (year < -999) year = -999;
snprintf(result, size, "%04d-%02d-%02dT%02d:%02d:%02d.000", year, (me->tm_mon + 1)&31, me->tm_mday&31, me->tm_hour&31,
me->tm_min&63, me->tm_sec&63);
return result;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment