[clang] [NFC] Avoid potential null dereference. (PR #126872)

Björn Schäpers via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 13 12:04:31 PST 2025


================
@@ -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))
----------------
HazardyKnusperkeks wrote:

As owen said, we need a test case.

If `Line` starts with a closing namespace, I don't see how there could not be a `PreviousLine`.

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


More information about the cfe-commits mailing list