[all-commits] [llvm/llvm-project] a9bef0: [clang-format] Fix incorrect isspace input (NFC)

Kevin Cadieux via All-commits all-commits at lists.llvm.org
Wed Jun 29 10:21:32 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: a9bef0707db101bb72d000a1f09686d97fb2d35d
      https://github.com/llvm/llvm-project/commit/a9bef0707db101bb72d000a1f09686d97fb2d35d
  Author: Kevin Cadieux <kevca at microsoft.com>
  Date:   2022-06-29 (Wed, 29 Jun 2022)

  Changed paths:
    M clang/lib/Format/FormatTokenLexer.cpp

  Log Message:
  -----------
  [clang-format] Fix incorrect isspace input (NFC)

This change fixes a clang-format unit test failure introduced by [D124748](https://reviews.llvm.org/D124748). The `countLeadingWhitespace` function was calling `isspace` with values that could fall outside the valid input range. The valid input range for `isspace` is unsigned 0-255. Values outside this range produce undefined behavior, which on Windows manifests as an assertion being raised in the debug runtime libraries. `countLeadingWhitespace` was calling `isspace` with a signed char that could produce a negative value if the underlying byte's value was 128 or above, which can happen for non-ASCII encodings. The fix is to use `StringRef`'s `bytes_begin` and `bytes_end` iterators to read the values as unsigned chars instead.

This bug can be reproduced by building the `check-clang-unit` target with a DEBUG configuration under Windows. This change is already covered by existing unit tests.

Reviewed By: MyDeveloperDay

Differential Revision: https://reviews.llvm.org/D128786




More information about the All-commits mailing list