[sanitizer] Avoid extra newlines in syslog.
authorEvgeniy Stepanov <eugeni.stepanov@gmail.com>
Fri, 12 Oct 2018 22:07:54 +0000 (22:07 +0000)
committerEvgeniy Stepanov <eugeni.stepanov@gmail.com>
Fri, 12 Oct 2018 22:07:54 +0000 (22:07 +0000)
Fix line splitting logic to avoid sending empty lines to syslog, as
that adds extra newlines.

llvm-svn: 344426

compiler-rt/lib/sanitizer_common/sanitizer_common_libcdep.cc

index 796a054..ab42b21 100644 (file)
@@ -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() {