1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-09 00:00:04 +01:00

use gmtime_r instead of gmtime if possible

Also check tm result is not NULL before using it.
This commit is contained in:
Pavel Otchertsov 2021-03-25 10:51:01 +03:00 committed by Andy Green
parent b5ed38395e
commit f84b90ba03
4 changed files with 18 additions and 9 deletions

View file

@ -552,6 +552,7 @@ CHECK_FUNCTION_EXISTS(_atoi64 LWS_HAVE__ATOI64)
CHECK_FUNCTION_EXISTS(_stat32i64 LWS_HAVE__STAT32I64)
CHECK_FUNCTION_EXISTS(clock_gettime LWS_HAVE_CLOCK_GETTIME)
CHECK_FUNCTION_EXISTS(localtime_r LWS_HAVE_LOCALTIME_R)
CHECK_FUNCTION_EXISTS(gmtime_r LWS_HAVE_GMTIME_R)
CHECK_FUNCTION_EXISTS(ctime_r LWS_HAVE_CTIME_R)
CHECK_FUNCTION_EXISTS(getgrgid_r LWS_HAVE_GETGRGID_R)
CHECK_FUNCTION_EXISTS(getgrnam_r LWS_HAVE_GETGRNAM_R)

View file

@ -51,6 +51,7 @@
#cmakedefine LWS_HAVE_EVP_PKEY_new_raw_private_key
#cmakedefine LWS_HAVE_EXECVPE
#cmakedefine LWS_HAVE_LOCALTIME_R
#cmakedefine LWS_HAVE_GMTIME_R
#cmakedefine LWS_HAVE_CTIME_R
#cmakedefine LWS_HAVE_GETGRGID_R
#cmakedefine LWS_HAVE_GETGRNAM_R

View file

@ -53,7 +53,14 @@ lws_http_date_render(char *buf, size_t len, const struct tm *tm)
int
lws_http_date_render_from_unix(char *buf, size_t len, const time_t *t)
{
#if defined(LWS_HAVE_GMTIME_R)
struct tm tmp;
struct tm *tm = gmtime_r(t, &tmp);
#else
struct tm *tm = gmtime(t);
#endif
if (!tm)
return -1;
if (lws_http_date_render(buf, len, tm))
return -1;

View file

@ -87,15 +87,15 @@ create_payload(uint8_t *buf, size_t s)
static void set_time(char *t)
{
/*20150830T123600Z*/
time_t rawtime;
struct tm *info;
time(&rawtime );
info = gmtime(&rawtime);
strftime(t ,20,"%Y%m%dT%H%M%SZ", info);
return;
time_t ti = time(NULL);
#if defined(LWS_HAVE_GMTIME_R)
struct tm tmp;
struct tm *tm = gmtime_r(&ti, &tmp);
#else
struct tm *tm = gmtime(&ti);
#endif
assert(tm);
strftime(t, 20, "%Y%m%dT%H%M%SZ", tm);
}
static void bin2hex(uint8_t *in, size_t len, char *out)