diff --git a/src/trace.c b/src/trace.c index f7dcb183..1aa89323 100644 --- a/src/trace.c +++ b/src/trace.c @@ -5,6 +5,7 @@ #include "trace.h" #include "mem.h" +#include "util.js.h" #include "sqlite3.h" #include "uv.h" @@ -138,7 +139,7 @@ void tf_trace_counter(tf_trace_t* trace, const char* name, int argc, const char* { p += snprintf(line + p, sizeof(line) - p, "\"%s\": %" PRId64 "%s", arg_names[i], arg_values[i], i == argc - 1 ? "}}," : ", "); } - + p = tf_min(p, _countof(line)); trace->callback(trace, line, p, trace->user_data); } @@ -279,6 +280,7 @@ static void _tf_trace_begin_tagged(tf_trace_t* trace, const char* name, void* ta int p = snprintf(line, sizeof(line), "{\"ph\": \"B\", \"pid\": %d, \"tid\": \"0x%" PRIx64 "\", \"ts\": %" PRId64 ", \"name\": \"", getpid(), (int64_t)self, _trace_ts()); p += _tf_trace_escape_name(line + p, sizeof(line) - p, name); p += snprintf(line + p, sizeof(line) - p, "\"},"); + p = tf_min(p, _countof(line)); trace->callback(trace, line, p, trace->user_data); } @@ -305,6 +307,7 @@ static void _tf_trace_end_tagged(tf_trace_t* trace, void* tag) int p = snprintf(line, sizeof(line), "{\"ph\": \"E\", \"pid\": %d, \"tid\": \"0x%" PRIx64 "\", \"ts\": %" PRId64 ", \"name\": \"", getpid(), (int64_t)pthread_self(), _trace_ts()); p += _tf_trace_escape_name(line + p, sizeof(line) - p, name); p += snprintf(line + p, sizeof(line) - p, "\"},"); + p = tf_min(p, _countof(line)); trace->callback(trace, line, p, trace->user_data); } diff --git a/src/util.js.h b/src/util.js.h index d616fea9..5b27e6db 100644 --- a/src/util.js.h +++ b/src/util.js.h @@ -22,4 +22,4 @@ const char* tf_util_backtrace_string(); const char* tf_util_function_to_string(void* function); -#define tf_min(a, b) ({ __typeof__ (a) _a = (a); __typeof__ (b) _b = (b); _a > _b ? _a : _b; }) +#define tf_min(a, b) ({ __typeof__ (a) _a = (a); __typeof__ (b) _b = (b); _a > _b ? _b : _a; })