[flang-commits] [flang] [flang] Avoid forming a reference from null pointer (PR #84787)

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Mon Mar 11 09:34:39 PDT 2024


================
@@ -136,7 +136,10 @@ void TokenSequence::Put(
 }
 
 void TokenSequence::Put(const CharBlock &t, Provenance provenance) {
-  Put(&t[0], t.size(), provenance);
+  // Avoid t[0] if t is empty: it would create a reference to nullptr,
+  // which is UB.
+  const char *addr = t.size() ? &t[0] : nullptr;
----------------
klausler wrote:

Use braced initialization in Flang front-end code.

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


More information about the flang-commits mailing list