Fixed log manager sometimes not writing the last character in a log message.

This was caused by type conversions from int to size_t and the usage of the MAX macro.
This commit is contained in:
Markus Makela 2015-02-20 04:42:02 +02:00
parent 093489d0d7
commit 3924f70d6b
6 changed files with 17 additions and 15 deletions

View File

@ -683,7 +683,7 @@ static int logmanager_write_log(
size_t safe_str_len;
/** Length of session id */
size_t sesid_str_len;
size_t cmplen = 0;
/**
* 2 braces, 2 spaces and terminating char
* If session id is stored to tls_log_info structure, allocate
@ -691,7 +691,7 @@ static int logmanager_write_log(
*/
if (id == LOGFILE_TRACE && tls_log_info.li_sesid != 0)
{
sesid_str_len = 2+2+get_decimal_len(tls_log_info.li_sesid)+1;
sesid_str_len = 5*sizeof(char)+get_decimal_len(tls_log_info.li_sesid);
}
else
{
@ -699,14 +699,16 @@ static int logmanager_write_log(
}
timestamp_len = get_timestamp_len();
cmplen = sesid_str_len > 0 ? sesid_str_len - sizeof(char) : 0;
/** Find out how much can be safely written with current block size */
if (timestamp_len-1+MAX(sesid_str_len-1,0)+str_len > lf->lf_buf_size)
if (timestamp_len-sizeof(char)+cmplen+str_len > lf->lf_buf_size)
{
safe_str_len = lf->lf_buf_size;
}
else
{
safe_str_len = timestamp_len-1+MAX(sesid_str_len-1,0)+str_len;
safe_str_len = timestamp_len-sizeof(char)+cmplen+str_len;
}
/**
* Seek write position and register to block buffer.

View File

@ -157,7 +157,7 @@ static bool do_hashtest(
CHK_HASHTABLE(h);
hashtable_free(h);
return_succp:
free(val_arr);
return succp;
}

View File

@ -32,7 +32,7 @@
#include <string.h>
#include <server.h>
#include <log_manager.h>
/**
* test1 Allocate a server and do lots of other things
*

View File

@ -187,7 +187,7 @@ int main(int argc, char** argv){
}
instance.thrpool = t_thr_pool;
int thr_num = 1;
intptr_t thr_num = 1;
for(i = 0;i<instance.thrcount;i++){

View File

@ -31,7 +31,7 @@
const char* timestamp_formatstr = "%04d-%02d-%02d %02d:%02d:%02d ";
/** One for terminating '\0' */
const int timestamp_len = 4+1 +2+1 +2+1 +2+1 +2+1 +2+3 +1;
const size_t timestamp_len = (4+1 +2+1 +2+1 +2+1 +2+1 +2+3 +1) * sizeof(char);
/** Single-linked list for storing test cases */
@ -662,7 +662,7 @@ bool mlist_cursor_move_to_first(
/** End of mlist */
int get_timestamp_len(void)
size_t get_timestamp_len(void)
{
return timestamp_len;
}
@ -682,13 +682,13 @@ int get_timestamp_len(void)
* @details (write detailed description here)
*
*/
int snprint_timestamp(
size_t snprint_timestamp(
char* p_ts,
int tslen)
size_t tslen)
{
time_t t;
struct tm tm;
int rval;
size_t rval;
if (p_ts == NULL) {
rval = 0;
@ -708,7 +708,7 @@ int snprint_timestamp(
tm.tm_min,
tm.tm_sec);
rval = strlen(p_ts);
rval = strlen(p_ts)*sizeof(char);
retblock:
return rval;
}

View File

@ -124,8 +124,8 @@ int skygw_thread_start(skygw_thread_t* thr);
skygw_thr_state_t skygw_thread_get_state(skygw_thread_t* thr);
pthread_t skygw_thread_gettid(skygw_thread_t* thr);
int get_timestamp_len(void);
int snprint_timestamp(char* p_ts, int tslen);
size_t get_timestamp_len(void);
size_t snprint_timestamp(char* p_ts, size_t tslen);
EXTERN_C_BLOCK_BEGIN