Properly fix string truncation in snprint_timestamp
The length of the timestamp string had a practical meaning. The correct fix was to always use the length passed as the parameter.
This commit is contained in:
@ -46,12 +46,11 @@ typedef enum { MES_RC_FAIL, MES_RC_SUCCESS, MES_RC_TIMEOUT } skygw_mes_rc_t;
|
|||||||
|
|
||||||
static const char* timestamp_formatstr = "%04d-%02d-%02d %02d:%02d:%02d ";
|
static const char* timestamp_formatstr = "%04d-%02d-%02d %02d:%02d:%02d ";
|
||||||
/** One for terminating '\0' */
|
/** One for terminating '\0' */
|
||||||
static const size_t timestamp_len = (4 + 1 + 2 + 1 + 2 + 1 + 2 + 1 + 2 + 1 + 2 + 3 + 1 + 16) * sizeof(char);
|
static const size_t timestamp_len = (4 + 1 + 2 + 1 + 2 + 1 + 2 + 1 + 2 + 1 + 2 + 3 + 1);
|
||||||
|
|
||||||
static const char* timestamp_formatstr_hp = "%04d-%02d-%02d %02d:%02d:%02d.%03d ";
|
static const char* timestamp_formatstr_hp = "%04d-%02d-%02d %02d:%02d:%02d.%03d ";
|
||||||
/** One for terminating '\0' */
|
/** One for terminating '\0' */
|
||||||
static const size_t timestamp_len_hp = (4 + 1 + 2 + 1 + 2 + 1 + 2 + 1 + 2 + 1 + 2 + 1 + 3 + 3 + 1 + 16) *
|
static const size_t timestamp_len_hp = (4 + 1 + 2 + 1 + 2 + 1 + 2 + 1 + 2 + 1 + 2 + 1 + 3 + 3 + 1);
|
||||||
sizeof(char);
|
|
||||||
|
|
||||||
struct skygw_thread_st
|
struct skygw_thread_st
|
||||||
{
|
{
|
||||||
|
@ -84,7 +84,7 @@ size_t snprint_timestamp(char* p_ts, size_t tslen)
|
|||||||
|
|
||||||
t = time(NULL);
|
t = time(NULL);
|
||||||
localtime_r(&t, &tm);
|
localtime_r(&t, &tm);
|
||||||
snprintf(p_ts, MXS_MIN(tslen, timestamp_len), timestamp_formatstr,
|
snprintf(p_ts, tslen, timestamp_formatstr,
|
||||||
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour,
|
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour,
|
||||||
tm.tm_min, tm.tm_sec);
|
tm.tm_min, tm.tm_sec);
|
||||||
rval = strlen(p_ts) * sizeof (char);
|
rval = strlen(p_ts) * sizeof (char);
|
||||||
@ -125,7 +125,7 @@ size_t snprint_timestamp_hp(char* p_ts, size_t tslen)
|
|||||||
gettimeofday(&tv, NULL);
|
gettimeofday(&tv, NULL);
|
||||||
localtime_r(&tv.tv_sec, &tm);
|
localtime_r(&tv.tv_sec, &tm);
|
||||||
usec = tv.tv_usec / 1000;
|
usec = tv.tv_usec / 1000;
|
||||||
snprintf(p_ts, MXS_MIN(tslen, timestamp_len_hp), timestamp_formatstr_hp,
|
snprintf(p_ts, tslen, timestamp_formatstr_hp,
|
||||||
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
|
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
|
||||||
tm.tm_hour, tm.tm_min, tm.tm_sec, usec);
|
tm.tm_hour, tm.tm_min, tm.tm_sec, usec);
|
||||||
rval = strlen(p_ts) * sizeof (char);
|
rval = strlen(p_ts) * sizeof (char);
|
||||||
|
Reference in New Issue
Block a user