From 9ab897dcb577d2d9044dbf13f6c7dc78bd659487 Mon Sep 17 00:00:00 2001 From: Evgeniy Stepanov Date: Fri, 12 Oct 2018 22:07:54 +0000 Subject: [PATCH] [sanitizer] Avoid extra newlines in syslog. Fix line splitting logic to avoid sending empty lines to syslog, as that adds extra newlines. llvm-svn: 344426 --- .../lib/sanitizer_common/sanitizer_common_libcdep.cc | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_libcdep.cc b/compiler-rt/lib/sanitizer_common/sanitizer_common_libcdep.cc index 796a054..ab42b2167 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_common_libcdep.cc +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_libcdep.cc @@ -100,14 +100,17 @@ void WriteToSyslog(const char *msg) { // Print one line at a time. // syslog, at least on Android, has an implicit message length limit. - do { - q = internal_strchr(p, '\n'); - if (q) - *q = '\0'; + while ((q = internal_strchr(p, '\n'))) { + *q = '\0'; + WriteOneLineToSyslog(p); + p = q + 1; + } + // Print remaining characters, if there are any. + // Note that this will add an extra newline at the end. + // FIXME: buffer extra output. This would need a thread-local buffer, which + // on Android requires plugging into the tools (ex. ASan's) Thread class. + if (*p) WriteOneLineToSyslog(p); - if (q) - p = q + 1; - } while (q); } void MaybeStartBackgroudThread() { -- 2.7.4