Skip to content

Conversation

schittir
Copy link
Contributor

Add a null check.

@llvmbot
Copy link
Member

llvmbot commented Feb 12, 2025

@llvm/pr-subscribers-clang-format

Author: None (schittir)

Changes

Add a null check.


Full diff: https://github.com/llvm/llvm-project/pull/126872.diff

1 Files Affected:

  • (modified) clang/lib/Format/UnwrappedLineFormatter.cpp (+1-1)
diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp b/clang/lib/Format/UnwrappedLineFormatter.cpp
index 46545aa1f4c07..a5b30c85974c7 100644
--- a/clang/lib/Format/UnwrappedLineFormatter.cpp
+++ b/clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -1596,7 +1596,7 @@ static auto computeNewlines(const AnnotatedLine &Line,
     if (Line.startsWith(TT_NamespaceRBrace)) {
       if (Style.WrapNamespaceBodyWithEmptyLines == FormatStyle::WNBWELS_Never)
         Newlines = 1;
-      else if (!PreviousLine->startsWith(TT_NamespaceRBrace))
+      else if (PreviousLine && !PreviousLine->startsWith(TT_NamespaceRBrace))
         Newlines = std::max(Newlines, 2u);
     }
   }

@schittir schittir merged commit f8c7457 into llvm:main Feb 12, 2025
10 checks passed
@owenca
Copy link
Contributor

owenca commented Feb 13, 2025

@schittir please add a test case that would cause a crash without your patch.

flovent pushed a commit to flovent/llvm-project that referenced this pull request Feb 13, 2025
schittir added a commit that referenced this pull request Feb 14, 2025
schittir added a commit that referenced this pull request Feb 14, 2025
Reverts #126872
The commit, though harmless, is unnecessary.
@schittir schittir deleted the static_analyzer_concerns branch February 14, 2025 17:34
github-actions bot pushed a commit to arm/arm-toolchain that referenced this pull request Feb 14, 2025
joaosaffran pushed a commit to joaosaffran/llvm-project that referenced this pull request Feb 14, 2025
joaosaffran pushed a commit to joaosaffran/llvm-project that referenced this pull request Feb 14, 2025
Reverts llvm#126872
The commit, though harmless, is unnecessary.
sivan-shani pushed a commit to sivan-shani/llvm-project that referenced this pull request Feb 24, 2025
sivan-shani pushed a commit to sivan-shani/llvm-project that referenced this pull request Feb 24, 2025
Reverts llvm#126872
The commit, though harmless, is unnecessary.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants