[all-commits] [llvm/llvm-project] 920146: [lldb] Don't rely on wrapping in PutRawBytes/PutBy...

Jonas Devlieghere via All-commits all-commits at lists.llvm.org
Tue Feb 15 20:38:38 PST 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 920146316da1e55017d46cfd62be783419da03d5
      https://github.com/llvm/llvm-project/commit/920146316da1e55017d46cfd62be783419da03d5
  Author: Jonas Devlieghere <jonas at devlieghere.com>
  Date:   2022-02-15 (Tue, 15 Feb 2022)

  Changed paths:
    M lldb/source/Utility/Stream.cpp
    M lldb/unittests/Utility/StreamTest.cpp

  Log Message:
  -----------
  [lldb] Don't rely on wrapping in PutRawBytes/PutBytesAsRawHex8

I was looking at Stream::PutRawBytes and thought I spotted a bug because
both loops are using `i < src_len` as the loop condition despite them
iterating in opposite directions.

On closer inspection, the existing code is correct, because it relies on
well-defined unsigned integer wrapping. Correct doesn't mean readable,
so this patch changes the loop condition to compare against 0 when
decrementing i while still covering the edge case of src_len potentially
being 0 itself.

Differential revision: https://reviews.llvm.org/D119857




More information about the All-commits mailing list