Skip to content

[NFC] Avoid potential null dereference. #126872

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 12, 2025

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