From 1135331ce6a579ceacf0f250c53df1f7a02abe93 Mon Sep 17 00:00:00 2001 From: Andrew Noyes Date: Thu, 11 Apr 2019 10:01:06 -0700 Subject: [PATCH 1/3] Include space as a printable character --- flow/Trace.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flow/Trace.h b/flow/Trace.h index 5037621ae9..66666aa259 100644 --- a/flow/Trace.h +++ b/flow/Trace.h @@ -294,7 +294,7 @@ struct TraceableString { template struct TraceableStringImpl : std::true_type { - static constexpr bool isPrintable(char c) { return c > 32 && c < 127; } + static constexpr bool isPrintable(char c) { return 32 <= c && c <= 126; } template static std::string toString(Str&& value) { From 369c1a02306c8a00c4b4ae780f8249eb4ed937e0 Mon Sep 17 00:00:00 2001 From: Andrew Noyes Date: Thu, 11 Apr 2019 10:39:48 -0700 Subject: [PATCH 2/3] Exclude trailing \0 byte for string literals This will "do the right thing" as long as no one expects something like char a[] = {'a'}; TraceEvent("Event").detail("a", a); to trace `{..., "a": "a"}`. It will trace `{..., "a": ""}` --- flow/Trace.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/flow/Trace.h b/flow/Trace.h index 66666aa259..b26699f6bd 100644 --- a/flow/Trace.h +++ b/flow/Trace.h @@ -269,11 +269,11 @@ struct TraceableString { } static bool atEnd(const char* value, const char* iter) { - return iter - value == S; + return iter - value == S - 1; // Exclude trailing \0 byte } static std::string toString(const char* value) { - return std::string(value, S); + return std::string(value, S - 1); // Exclude trailing \0 byte } }; From dced9232d06e24f382e806f641d64f1a003b11a8 Mon Sep 17 00:00:00 2001 From: Andrew Noyes Date: Mon, 15 Apr 2019 09:43:26 -0700 Subject: [PATCH 3/3] ASSERT_WE_THINK trailing byte is '\0' --- flow/Trace.cpp | 5 +++++ flow/Trace.h | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/flow/Trace.cpp b/flow/Trace.cpp index cca638f7ad..0872a502ae 100644 --- a/flow/Trace.cpp +++ b/flow/Trace.cpp @@ -1218,3 +1218,8 @@ void TraceEventFields::validateFormat() const { } } } + +std::string traceableStringToString(const char* value, size_t S) { + ASSERT_WE_THINK(value[S - 1] == '\0'); + return std::string(value, S - 1); // Exclude trailing \0 byte +} diff --git a/flow/Trace.h b/flow/Trace.h index b26699f6bd..69ee6175cf 100644 --- a/flow/Trace.h +++ b/flow/Trace.h @@ -262,6 +262,8 @@ struct TraceableString { } }; +std::string traceableStringToString(const char* value, size_t S); + template struct TraceableString { static const char* begin(const char* value) { @@ -272,9 +274,7 @@ struct TraceableString { return iter - value == S - 1; // Exclude trailing \0 byte } - static std::string toString(const char* value) { - return std::string(value, S - 1); // Exclude trailing \0 byte - } + static std::string toString(const char* value) { return traceableStringToString(value, S); } }; template<>