[Lldb-commits] [lldb] 35a0614 - [lldb/Utility] Fix unspecified behavior.

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Mon Feb 24 21:31:41 PST 2020


Author: Jonas Devlieghere
Date: 2020-02-24T21:25:55-08:00
New Revision: 35a061453579f623aca1edc7f6f23dd969c21395

URL: https://github.com/llvm/llvm-project/commit/35a061453579f623aca1edc7f6f23dd969c21395
DIFF: https://github.com/llvm/llvm-project/commit/35a061453579f623aca1edc7f6f23dd969c21395.diff

LOG: [lldb/Utility] Fix unspecified behavior.

Order of evaluation of the operands of any C++ operator [...] is
unspecified. This patch fixes the issue in Stream::Indent by calling the
function consecutively.

On my Windows setup, TestSettings.py fails because the function prints
the value first, followed by the indentation.

Expected result:
  MY_FILE=this is a file name with spaces.txt

Actual result:
MY_FILE  =this is a file name with spaces.txt

Added: 
    

Modified: 
    lldb/source/Utility/Stream.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/source/Utility/Stream.cpp b/lldb/source/Utility/Stream.cpp
index 8d32b5674502..8c09eadcebd8 100644
--- a/lldb/source/Utility/Stream.cpp
+++ b/lldb/source/Utility/Stream.cpp
@@ -127,8 +127,9 @@ size_t Stream::PrintfVarArg(const char *format, va_list args) {
 size_t Stream::EOL() { return PutChar('\n'); }
 
 size_t Stream::Indent(llvm::StringRef str) {
-  std::string indentation(m_indent_level, ' ');
-  return PutCString(indentation) + PutCString(str);
+  const size_t ind_length = PutCString(std::string(m_indent_level, ' '));
+  const size_t str_length = PutCString(str);
+  return ind_length + str_length;
 }
 
 // Stream a character "ch" out to this stream.


        


More information about the lldb-commits mailing list